try the code below.
I use AutoCompleteText to automatically complete the location where the user is located, locationList is nothing more than an array that I wrote in the strings.xml file, so here use your own array of strings.
locationList = res.getStringArray(R.array.ticketLocation); ArrayAdapter<String> locationAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, locationList); AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.txtCountries); textView.setThreshold(1); textView.setAdapter(locationAdapter); textView.setValidator(new Validator()); textView.setOnFocusChangeListener(new FocusListener()); textView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
and below is the code for checking text input in the location field, the fixText () method does not allow the user to enter text that does not exist in your string array, for example: if the user enters "germany", which does not exist in the list of string arrays, he will be replaced by "", which is an empty string inside the edittext input field
class Validator implements AutoCompleteTextView.Validator { @Override public boolean isValid(CharSequence text) {
Amadeus
source share