0

I am trying to remove the accentuation of the searcher's words, but my code is not working.

I would like you to look up an example word Você all of the variations of it Voce, Você, voce, você, VOCE, VOCÊ.

    @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);

}

1 Answers1

0

As you can see here (Remove diacritical marks (ń ǹ ň ñ ṅ ņ ṇ ṋ ṉ ̈ ɲ ƞ ᶇ ɳ ȵ) from Unicode chars), you can use the java.text package to do this. You first remove diactrical marks, then convert to ascii. Non-ascii characters will become question marks.

Emmanuel H
  • 82
  • 8