2011-10-11 60 views
5
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; 
     } 
    }); 

我不會進入onItemSelected。 我需要得到我的列表中的哪一個是按位置選擇的,以獲得id。MultiAutoCompleteTextView不能正常工作OnItemSelectedListener

回答

2

OnItemSelectedListener永遠不會被AutoCompleteTextView(或MultiAutoCompleteTextView)觸發。改用OnItemClickListener:

setOnItemClickListener(new AdapterView.OnItemClickListener() { 
    @Override 
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 
     Object item = parent.getItemAtPosition(position); 
    } 
});