我正在使用自動完成功能從Google API獲取地點。它的工作很好。它提取所有的地方下降,但事情是,如果我點擊該項目,onItemClick偵聽器不工作的自動完成。自動完成onItemClickListener事件不觸發?
這是代碼
ArrayList<String> values=new ArrayList<String>();
for(int i=0;i<result.size();i++)
{
values.add(result.get(i).get("description"));
}
PlacesAdapter placesAdapter=new PlacesAdapter(getActivity(),values);
// Setting the adapter
tempAutoCompleteTextView.setDropDownVerticalOffset(20);
tempAutoCompleteTextView.setAdapter(placesAdapter);
tempAutoCompleteTextView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getActivity(), "place"+postion, Toast.LENGTH_SHORT).show();
tempAutoCompleteTextView.setText(result.get(position).get("description"));
}
});
此代碼是PlacesAdapter
的public class PlacesAdapter extends ArrayAdapter {
private ArrayList<String> list;
private Activity mContext;
public PlacesAdapter(Activity context,ArrayList<String> list) {
super(context,list.size(),list);
this.list = list;
mContext = context;
}
您正在使用自定義視圖嗎? – Bharatesh