Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MultiAutoCompleteTextView not working OnItemSelectedListener

ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(Application.getContext(), R.layout.report_add_list_item, ListUtil.asStringList(ContactServiceUtil.getContacts()));
    multiAutoCompleteContacts = (MultiAutoCompleteTextView) findViewById(R.id.multiAutoCompleteGuests);
    multiAutoCompleteContacts.setAdapter(adapter1);
    multiAutoCompleteContacts.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
    multiAutoCompleteContacts.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            System.out.println("click");
        }

        public void onNothingSelected(AdapterView<?> adapterView) {
            return;
        }
    });

I do not go inside of onItemSelected. I need to get which one of my list is selected by position, to get the id.

like image 216
nayden Avatar asked Nov 05 '22 13:11

nayden


1 Answers

OnItemSelectedListener is never triggered by AutoCompleteTextView (or MultiAutoCompleteTextView). Use OnItemClickListener instead:

setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        Object item = parent.getItemAtPosition(position);
    }
});
like image 189
Greg Avatar answered Nov 15 '22 04:11

Greg