2015-05-18 197 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。 –