This is the code for my AutoCompleteTextView :
String[] countries = getResources().getStringArray(R.array.countries_array);
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.item_list ,countries);
textView = (AutoCompleteTextView) dialog.findViewById(R.id.autoCompleteTextView1);
adapter.setNotifyOnChange(true);
textView.setAdapter(adapter);
This is item_list :
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:textSize="16sp"
android:textColor="#000"
android:drawableRight="@drawable/arrow">
and this is the output :
I want to change this pop-up kind of suggestion box , and want to show the suggestion list a little bit below from the AutoCompleteTextView ..similar to this : (please disregard the apple design, it’s just about where the results appear)
How can i do this ..Please suggest . Thanks.!!
If you want to get suggestions , when you type in an editable text field , you can do this via AutoCompleteTextView. It provides suggestions automatically when 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.
OnItemClickListener and set onItemClickListener() on the AutoCompleteTextView to get the user selected item value from the list. Notice that while using the ArrayAdapter , we have provided a layout object as argument android. R.
This defines the hint view displayed in the drop down menu. This defines the number of characters that the user must type before completion suggestions are displayed in a drop down menu. This is the View to anchor the auto-complete dropdown to.
Use the android:dropDownAnchor
, android:dropDownHorizontalOffset
, android:dropDownVerticalOffset
and maybe others on the AutoCompleteTextView
in your layout. See AutocompleteTextView.
I used a ListView below the AutoCompleteTextView. I added my custom adapter to both the ListView and the AutoCompleteTextView. I the set the height and width of the AutoCompleteTextView dropdown to 0:
myListView.setAdapter(myCustomAdapter);
myAutoComplete.setAdapter(myCustomAdapter);
myAutoComplete.setDropDownHeight(0);
myAutoComplete.setDropDownWidth(0);
Since the listview is also attached to the same adapter it'll get updated when you update the autocomplete.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With