Digit
Digit

Reputation: 1939

My list of words as suggestions to search view

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

Answers (2)

Jitender Dev
Jitender Dev

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

Razgriz
Razgriz

Reputation: 7343

Use an AutoCompleteTextView instead. Here is the link to the docs.

Upvotes: 0

Related Questions