zoukankan      html  css  js  c++  java
  • 大叔的第四天 @HTTP请求,JSON,LISTVIEW

    做了一个页面,同时用到了这三种不会的知识,写到这里。Map还要理解一下。

    public class SingleActivity extends Activity{
        private ListView listView;
        private ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>();
        SimpleAdapter adapter = null ;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            setContentView(R.layout.maintenance_single);
            listView = (ListView)findViewById(R.id.maintenance_single_list);
            List<NameValuePair> params = new ArrayList<NameValuePair>();
            //这里是网络请求的附加信息
            BasicNameValuePair pair1 = new BasicNameValuePair("UserAgent", Constands.UserAgent);//附加信息
            params.add(pair1);
            BasicNameValuePair pair2 = new BasicNameValuePair("Token", "34430000003165727730");//附加信息
            params.add(pair2);
            
            
    
            new HttpConnection().post("get_item", params,new HttpConnection.CallbackListener() {
    
                @Override
                public void callBack(String result) {
                    Log.v("post了",result);
                    if(result!="fail"){
                        try {
                            
                            
                            //JASON解析
                            JSONObject object = new JSONObject(result);
                            JSONArray content = object.getJSONArray("Content");
                            int cc = content.length();
                            
                            for(int i=0;i<cc;i++){
                                JSONObject objMap = content.getJSONObject(i);
                                HashMap<String,String> map = new HashMap<String,String>();
                                map.put("code",objMap.getString("code"));
                                map.put("name",objMap.getString("name"));
                                list.add(map);
                                Log.v("Content01",map.get("code"));
                                Log.v("Content01",map.get("name"));
                                
                            }
                            Log.v("TEST LIST",list.get(0).get("name"));
                        } catch (JSONException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                        adapter = new SimpleAdapter(
                                SingleActivity.this,
                                list,
                                R.layout.sositemrow,
                                new String[]{"name"},
                                new int[]{R.id.itemtitle});
                         
                        listView.setAdapter(SingleActivity.this.adapter);    
                        
                    }else{    
                    }    
                }    
            });    
            
        }
    } 
  • 相关阅读:
    mysql 事务只读: Could not retrieve transation read-only status server
    页面加载空白---(failed)net::ERR_INCOMPLETE_CHUNKED_ENCODING
    关于数据库mysql死锁:MySQLTransactionRollbackException: Lock wait timeout exceeded; try restarting transaction
    高性能分布式锁-redisson的使用
    C/S程序抓包
    linux 安装maven
    linux之jdk安装及环境
    腾讯云服务器搭建之mysql
    mysql去重保留id最小的
    MySQL中文全文检索
  • 原文地址:https://www.cnblogs.com/linxiaojiang/p/2950350.html
Copyright © 2011-2022 走看看