Remove accentuation of words in searchView

0

I'm trying to remove the accent from the searcher's words, but my code is not working.

I'd like you to look at a sample word Você all variations of Voce, Você, você, você, VOCE, VOCÊ .

Thank you

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater menuInflater = getMenuInflater();
        menuInflater.inflate(R.menu.busca, menu);

    MenuItem menuItem = menu.findItem(R.id.sv);

    SearchView searchView = (SearchView) menuItem.getActionView();
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
        //Irá tirar não só acentuações mas também qualquer caractere fora de ASCII
        String texto;
             texto = Normalizer.normalize(query, Normalizer.Form.NFD).replaceAll("[^\p{ASCII}]", "");

        //seu código

            return false;
        }

       //se for pra passar o texto já modificado para o arrayAdapter, vc faz:
        @Override
        public boolean onQueryTextChange(String newText) {
             String texto;
             texto = Normalizer.normalize(newText, Normalizer.Form.NFD).replaceAll("[^\p{ASCII}]", "");

            arrayAdapter.getFilter().filter(texto);
            return true;
        }
    });

    getMenuInflater().inflate(R.menu.activity_main, menu);
    return super.onCreateOptionsMenu(menu);

}
    
asked by anonymous 13.08.2018 / 14:32

1 answer

0

Try this

public static String stripAccents(String s) 
{
    s = Normalizer.normalize(s, Normalizer.Form.NFD);
    s = s.replaceAll("[\p{InCombiningDiacriticalMarks}]", "");
    return s;
}
    
14.08.2018 / 15:23