Rynardt Rynardt - 1 year ago 60
Android Question

AutoCompleteTextView detect when selected entry from list edited by user

I have an

I use to select an item from a long list. The user should only be able to select a predetermined item from the list. They should not be able to enter their own item.

The way I check to make sure they submit only an item from the list is to use
to trigger a boolean flag. The problem is that after the boolean flag is set to true, they can still edit the selected text of the item. I need to detect this and set the boolean flag to false again. How do I do this. I have seen a suggestion to use
, but I am not sure how to implement this.

Answer Source

You can add text changed listener:

autoCompleteTextView.addTextChangedListener(new TextWatcher() {

    public void onTextChanged(CharSequence s, int start, int before, int count) {


    public void beforeTextChanged(CharSequence s, int start, int count, int after) {                


    public void afterTextChanged(Editable s) {

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download