I am using AutoCompleteTextView in my application but it works unexpectedly. AutoComplete list show the unwanted text from list which i am not looking for but when i selected this text and remove focus from autocomletetextview than it set the proper text to the autocompletetext field. The other problem is that i want to gain the id of the selected text in the autocompletetext field i am associating this id when i am populating a list in the custom adaptor for autocompletetextview.
Here is the code i am using.
autoComMarker = (AutoCompleteTextView) findViewById(R.id.auto_rainfall_of_markaz_id);
autoComMarker.setThreshold(1);
CustomMarkazAdapter adapter = new CustomMarkazAdapter(getBaseContext(), R.layout.custom_auto_com_listview, marqazList);
autoComMarker.setAdapter(adapter);
autoComMarker.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View view,
int position, long arg3) {
autoComMarker.setTag(view.getTag());
Log.e("Markaz list", ""+view.getTag());
}
});
Here is the code for CustomMarkazAdapter:
public class CustomMarkazAdapter extends ArrayAdapter<Markaz>{
private ArrayList<Markaz> items;
private Context CurrentContext;
private Markaz CurrentItem;
public CustomMarkazAdapter(Context context, int textViewResourceId,
ArrayList<Markaz> objects) {
super(context, textViewResourceId, objects);
items = objects;
CurrentContext = context;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if ((items == null) || ((position + 1) > items.size()))
return convertView; //Can't extract item
CurrentItem = (Markaz)items.get(position);
LayoutInflater vi = (LayoutInflater)CurrentContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = vi.inflate(R.layout.custom_auto_com_listview, null);
TextView text = (TextView) convertView.findViewById(R.id.custom_auto_com_text);
text.setText(CurrentItem.getMarkazName());
convertView.setTag(CurrentItem.getMarkazID());
Log.e(CurrentItem.getMarkazName(),""+CurrentItem.getMarkazID());
return convertView;
}
}
The markazID i am setting here is not that i am looking for, its sets the markaz id according to the autocompletelistview item position.which i am not needed i need the markaz id which i am passed with the markazList.
Please help me, any help whould be very appreciated.
Try this.