I already made a list of phrases for autocomplete text view in android studio and i want the autocomplete to accept only phrases in this list For e.g if my array contain sarah,mike,adam And i wrote in the autocomplete text view omar .. the autocomplete text view will not accept it ..it will delete it .
Asked
Active
Viewed 36 times
0
-
Does this answer your question? [AutoCompleteTextView in android](https://stackoverflow.com/questions/9648347/autocompletetextview-in-android) – Sambhav Khandelwal May 02 '22 at 04:34
-
I didn't .. it's just for show suggestions even if write the second letter .. i edited my question to understand what i exactly want . Thank you – Mohammed Tayeb May 02 '22 at 12:11
1 Answers
1
you can try something like this:
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.yourLayout);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, PHRASES);
AutoCompleteTextView textView = (AutoCompleteTextView)
findViewById(R.id.yourTextView);
textView.setAdapter(adapter);
}
private static final String[] PHRASES = new String[] {
"Belgium", "France", "Italy", "Germany", "Spain"
};
Also you should take a look of the android developer site: AutoCompleteTextView

ladytoky0
- 588
- 6
- 16
-
This is just how to make autocomplete text view What i want is the autocomplete text view accept only phrases in my arrays .. for e.g in your code if i write China it won't accept it .. is that even possible in android studio? – Mohammed Tayeb May 02 '22 at 11:13