Disable Android AutoCompleteTextView after user selects item from drop down

前端 未结 5 1131
北海茫月
北海茫月 2021-02-07 06:47

I\'m using Android\'s AutoCompleteTextView with a CursorAdapter to add autocomplete to an app. In the view\'s onItemClickListener() (i.e.

5条回答
  •  粉色の甜心
    2021-02-07 07:47

    Answering my own question after a couple hours of hacking at this: It turns out you should implement your own OnItemClickListener and instead rely on the existing click listener to populate the TextView. I had originally implemented the onItemClickListener because it was using the results of Cursor.toString() to populate the text view. To change the output String, you should implement convertToString(Cursor) in your CursorAdapter. The CharSequence that gets returned will be populated in the text view.

    Doing this will also prevent the dropdown from showing up again (since setText() triggers the completion behavior but the default onItemClickListener does not).

提交回复
热议问题