Start a Project

AutoCompleteTextView


AutoCompleteTextView-

An editable text view that shows completion suggestions automatically while the user is typing. The list of suggestions is displayed in a drop-down menu from which the user can choose an item to replace the content of the edit box with. The drop-down list automatically dismisses when back key press.  AutoCompleteTextView Auto fill the item when the user clicks the item of the drop-down list.

The following snippet to add it to your layout.

We can add a threshold value (a number of characters) to start suggestion list while the user reached the threshold value (input the no. of characters).

Add array adapter to AutoCompleteTextView.

Adding Search Feature-

We can add the search icon to keyboard and handle them when the user clicks the search icon. the following snipped describe how to add the search feature to AutoCompleteTextView.

Firstly, We need to add search action to AutoCompleteTextView layout-

Now we need to add OnEditorActionListener when the user clicks the search icon on the keyboard then this listener will fire and execute onEditorAction function code. following snipped for the listener.

Performing Item Click Action-

You can perform some events as you need when User Clicks the drop-down Item. the following snippet shows the hide the keyboard and adds the Listener with Place result.

How it looks-

References:- https://developer.android.com/reference/android/widget/AutoCompleteTextView

Exit mobile version