batman
batman

Reputation: 4908

Autocomplete for the whole text view

Hi I'm very new to android and I'm trying to do the following. Provide some word completion for the sentence.

Here is the code I have for it:

private static final String[] COUNTRIES = new String[] {
    "Belgium", "France", "Italy", "Germany", "Spain"
};

// In the onCreate method
AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.actv_country);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, COUNTRIES);
textView.setAdapter(adapter);

where it automatically pop up when user types Belgium. But the problem I face is, when the user type this sentence:

Belgium France

for the first word Belgium the pop up comes, when I type France autocompletion doesnt work. Why?

Where I'm making the mistake?

Thanks in advance.

Upvotes: 0

Views: 120

Answers (2)

user3487063
user3487063

Reputation: 3682

You should use MultiAutoCompleteTextView for multiple words

Here is a good example of that

Comma is the default separator for MultiAutoComplete, you can set it to space delimiter, please have a look at this post to achieve that.

Have a look at this post to for space delimiter.

Upvotes: 1

asylume
asylume

Reputation: 544

You are searching for "Belgium France", but you don't have this item in your list (in one String object). You will have to create custom Adapter which implements Filterable with custom Filter.

Upvotes: 0

Related Questions