Skip to content Skip to sidebar Skip to footer

Autocompletetextview Item Selection Trigger Event

I want an error on TextInputLayout to be disabled when an item is selected from AutoCompleteTextView This is googles documentation on AdapterView.OnItemClickListener. https://devel

Solution 1:

Use the setOnItemClickListener listener:

autoComplete.setOnItemClickListener(newAdapterView.OnItemClickListener() {
    @OverridepublicvoidonItemClick(AdapterView<?> adapterView, View view, int position, long id) {
        //do something...
    }
});

Since you are using a Material Component Theme the AutoCompleteTextView is replaced at runtime by the MaterialAutoCompleteTextView.

As you can check in the code when an item in the Popup is selected the OnItemClickListener interface is called.

Solution 2:

When you click on an item on the adapter it is not a Selection but a click event

use this to remove the Error when the items are clicked by adding mtextInputLayout.setError(null) on the click listener:

autoComplete.setOnItemClickListener(newAdapterView.OnItemClickListener() {
    @OverridepublicvoidonItemClick(AdapterView<?> parent, View view, int position, long id) {
        mtextInputLayout.setError(null);
    }
});

Post a Comment for "Autocompletetextview Item Selection Trigger Event"