Reputation: 1939
I have a list of words and a SearchView
.
When the user is typing a word, I want to suggest a list of words which starts with user entered characters. It is possible with Edittext, but how can I get it in SearchView
?
Upvotes: 1
Views: 432
Reputation: 6925
You can achieve this using AutoCompleteTextView
In your layout , use this
<AutoCompleteTextView
android:id="@+id/autocompletetextview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="" >
</AutoCompleteTextView>
and use below code in your activity
AutoCompleteTextView autocompletetextview;
String[] array = { "One", "Two", "Three", "Four", "Five", "Six", "Seven",
"Eight", "Nine", "Ten" };
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
autocompletetextview = (AutoCompleteTextView) findViewById(R.id.autocompletetextview);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.select_dialog_item, array);
autocompletetextview.setThreshold(1);
autocompletetextview.setAdapter(adapter);
Upvotes: 2