0

对不起....我是android的新手....

我已经完成了这样的架构:我在我的活动中创建了列表视图,并像在所有教程中一样将它放在带有自己活动的适配器上......

但是现在我必须走得更远,创建更复杂的活动:在我的每个列表视图适配器视图上,我必须放置另一个带有数据的循环 => 其他带有适配器的列表视图......这是真的吗?

这是我的代码(我在教育目标中这样做):

protected void onCreate(Bundle savedInstanceState) {
        String bank;
        bank = this.getIntent().getStringExtra("Bank_id");
        url = "http://192.168.1.4:3000/exchanger_lists/get_bank_exchanger_list/"+bank+".json";
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bank_exchangers_list);

        // Hashmap for ListView
        ArrayList<HashMap<String, String>> contactList = new ArrayList<HashMap<String, String>>();

        // Creating JSON Parser instance
        JSONParser jParser = new JSONParser();

        // getting JSON string from URL
        JSONObject json = jParser.getJSONFromUrl(url);

        try {
            // Getting Array of Contacts
            banks = json.getJSONArray(TAG_Exchangers);

            // looping through All Contacts
            for(int i = 0; i < banks.length(); i++){
                JSONObject c = banks.getJSONObject(i);

                // Storing each json item in variable
                String id = c.getString(TAG_ID);
                String name = c.getString(TAG_NAME);
                String address = c.getString(TAG_address);
                String location_name = c.getString(TAG_location_name);
                String latitude = c.getString(TAG_latitude);
                String longitude = c.getString(TAG_longitude);
                String exchanger_type_name = c.getString(TAG_exchanger_type_name);

                HashMap<String, String> map = new HashMap<String, String>();


                map.put(TAG_ID, id);
                map.put(TAG_NAME, name);
                map.put(TAG_address, address);
                map.put(TAG_location_name, location_name);
                map.put(TAG_latitude, latitude);
                map.put(TAG_longitude, longitude);
                map.put(TAG_exchanger_type_name, exchanger_type_name);


                // adding HashList to ArrayList
                contactList.add(map);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }


        ListAdapter adapter = new SimpleAdapter(this, contactList,
                R.layout.bank_exchanger_list_element,
                new String[] { TAG_NAME, TAG_location_name, TAG_address, TAG_exchanger_type_name, TAG_latitude, TAG_longitude }, new int[] {
                        R.id.bank_e_n, R.id.nas_punkt_e_n , R.id.adress_obm_e_n , R.id.tip_obm_e_n , R.id.shirota_e_n , R.id.dolgota_e_n });

        setListAdapter(adapter);
    }

我需要为每个 TAG_Exchangers 解析 json 子项,并添加为适配器 listAdapter adapter = new SimpleAdapter(this, contactList, ..

这是真的吗?怎么做?

4

1 回答 1

0

why not using BaseAdapter , where you rule everything related to how it looks and how it uses the data? just implement getCount,getItem, and getView .

for more information about listView, watch "the world of listView" lecture.

于 2013-04-27T13:27:00.323 回答