2015-05-18 119 views
-2

我想從下面的Json獲取countryId,countryName的詳細信息(請參閱截圖:http://i.imgur.com/DDs9rGT.png)。這是我的代碼:http://prntscr.com/76jbm4 這裏: ArrayList companyName = new ArrayList(); AutoCompleteTextView country_editText; 此AutoCompleteTextView向用戶顯示國家名稱列表,我想獲取用戶選擇的國家/地區的countryId。從Json獲取數據

問題是我無法傳遞由countryId和countryName組成的AutoCompleteTextView的列表。

+0

http://prntscr.com/76jbm4這是什麼鏈接?它不適用於我 –

+0

你有什麼錯誤嗎? – Muthu

+0

而不是傳遞多個值只傳遞CountyList並使用indexOf來查找列表的ID。 – Muthu

回答

1

創建一個模型類

class country{ 

private String countryName; 
private String countryPhonecode; 
private int countryId; 
private String countryCode; 

//getters and setters  
} 
List<Country> countryNameList=new ArrayList<Country>(); 

for(int i=0;i<yourArray;i++){ 
JSONObject json=array.getJSONObject(i); 
country c=new country(); 
c.setcountryName(json.getString("countryName")); 
//do same with all parameter 

countryNameList.add(c);  
} 

and Now use indexOf to find id of the list like that. 

list.get(position).getCountryId(). 

我希望這會幫助你。

+0

感謝您的回答。根據我的經驗,我沒有使用indexOf。您能否請我解釋一下我如何使用它 –

+0

list.get(position).getCountryId()。在這裏你能解釋一下,我怎樣才能得到位置 –

+0

@ParthibanM的值,當你點擊任何一個列表項時,它總是返回一個位置,告訴你該索引。並在該索引的幫助下可以獲得國家級對象。當您獲得對象時,現在您無法通過國家/地區類的getCountryId()方法獲取國家/地區ID。 –