Autocompletetextview display items that have accent when typed without accent

Asked

Viewed 303 times

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

  • 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?

  • Hmm, dough, how’s your Adapter? I think you’ll probably need to create a Adapter customized for this.

  • I updated the question with the code snippet.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.