我已从服务器中的数据填充了AutCompleteTextView
。从Autocomplete TextViewt
选择制造商并显示Toast以显示选择了哪个项目时,所选制造商提取的基于服务器的ID不正确。
例如:
如果我从autocomplete dropdown
选择“Voillant”,Toast会显示“Voillant”然后获得“Worchester Borsch”的ID(我automcomplete textview
中的另一个制造商。
@Override
public void onItemClick(AdapterView<?> parent, View arg1,
int position, long arg3)
{
Toast.makeText(parent.getContext(), "Manufacturer is " + parent.getItemAtPosition(position).toString(),
Toast.LENGTH_LONG).show();
int theIdMan =idListMan.get(position);
conv_to_str_id_man = String.valueOf(theIdMan);
Log.d(" check id ", conv_to_str_id_man);
}
获取ID的代码
JSONArray JA=new JSONArray(result);
JSONObject json= null;
final List<Integer> idListMan = new ArrayList<Integer>(); // id saved in array list of Ints
final List<String> list2Man = new ArrayList<String>();
for(int i=0;i<JA.length();i++)
{
json=JA.getJSONObject(i);
idListMan.add(json.getInt("manufacturers_id")); //getting id from JSON
list2Man.add(json.getString("manufacturers_name"));
}
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.man_list_auto_com , list2Man);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
text.setThreshold(0);
text.setAdapter(dataAdapter);
text.setOnItemClickListener(new OnItemClickListener()
{