0
對不起....我在Android的新....的Android的ListView適配器(JSON兒童)
我曾做過這樣的模式: 我在活動中創建列表視圖,並把它適配器與所有教程中的自己的活動...
但現在我必須進一步創建更復雜的活動:在我的每一個listview適配器視圖我必須把另一個循環與數據=>其他listview與適配器...是它是真的嗎?
這裏是我的代碼(我做教育的目標):
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);
}
我需要解析json的孩子每個TAG_Exchangers並添加作爲適配器listAdapter適配器=新SimpleAdapter適配器(這一點,contactList ,.......
是真的嗎?怎麼辦呢?
hm ....複雜...爲什麼Base?如何把它放在一個更多的集合?你可以給代碼嗎? – 2013-04-27 14:12:42
剛剛閱讀了baseAdapter samples.i'm不知道你想要它是多麼複雜,所以我認爲你需要baseAdapter。也許你沒有。關於使用新的項目列表,請創建適配器的新實例並調用listView.setAdapter,或者在適配器類中設置列表並調用adapter.notifyDataSetChanged()。 – 2013-04-27 14:32:06