1
I own a AutoCompleteTextView
, defined as your Adapter I have a list that receives the name of cities as, for example, São Paulo, but if I inform you in the field the value Sao Paulo, without the accent, it does not display any item, that’s why probably the AutoCompleteTextView
does not identify the character a == ã
.
How can I make the accent value appear when the accent value is entered?
Code I created separately for testing:
ArrayList<String>cidades = new ArrayList<>();
cidades.add("São Paulo");
cidades.add("São Luiz");
autoComplete = (AppCompatAutoCompleteTextView)findViewById(R.id.autoComplete);
ArrayAdapter<String> lista = new ArrayAdapter<>(this,android.R.layout.simple_dropdown_item_1line,cidades);
autoComplete.setAdapter(lista);
P.S.: I can add the items without accent to the list easily.
I see two alternatives, the two have their points to think about. It is a fact that the comparison has to be done ignoring accents. But this does not imply that you need to store the list value without accents. The first alternative is to remove accents when comparing. The other is to store the values with and without accent, and when comparing, to use the without accent. Depending on the amount of data, it is worth spending a little more memory or spending a little more cpu. Ah and to remove accents, this answer will help a lot: http://stackoverflow.com/questions/8523631/remove-accents-from-string
– Wakim
Well the list with the values with and without accents I already own, it is filled with information from my database that already has a normalized column with the name without accent, but how do I implement the comparison without accents, with which class or method and the value displayed in autocompletetextview is the with the accent?
– Rafael
Hmm, dough, how’s your
Adapter
? I think you’ll probably need to create aAdapter
customized for this.– Wakim
I updated the question with the code snippet.
– Rafael