user3698465
user3698465

Reputation: 195

How can I limit the values of MultiAutoCompleteTextView to be only the items from my adapter?

This is the code I'm using:

MultiAutoCompleteTextView selectedCities = (MultiAutoCompleteTextView)findViewById(R.id.citiesSelected);

String[] cities = getResources().getStringArray(R.array.cities);

ArrayAdapter<String> adapter = new ArrayAdapter<String> (this,android.R.layout.simple_list_item_1,cities);
        selectedCities.setAdapter(adapter);
        selectedCities.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());

but when i want to add items it is possible to add any string not from my list...

I dont want to use Alert Dialog with MultiChoiceItems since I have more than 200 items on my list.

Thanks!!

Upvotes: 2

Views: 484

Answers (1)

Aurasphere
Aurasphere

Reputation: 4011

I know this is an old question but if you still have this problem, you can do this in at least two ways:

  1. You can add an onFocusChangeListener and then perform your validation inside of that.
  2. You can have your activity implement TextWatcher and then override:
@Override
public void afterTextChanged(Editable s) {
        // validation code goes here
}

About the last one, take a look at this question: Android: How can I validate EditText input?.

Upvotes: 1

Related Questions