The code of the previous answer works perfectly, however in the case in question it is necessary to convert both this newText String and the String that is inside the Adapter with which you will compare, in my case it was like this:
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.search_only_menu, menu);
MenuItem searchItem = menu.findItem(R.id.pesquisa_button);
SearchView searchView = (SearchView) searchItem.getActionView();
searchView.setImeOptions(EditorInfo.IME_ACTION_DONE); //Troca o botão de buscar para confirmar, já que a busca é em tempo real então não faz muito sentido ter o botão "pesquisar"
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String s) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
//Convertendo o texto de entrada para caracteres equivalentes sem acentuação, ç etc
String texto;
texto = Normalizer.normalize(newText, Normalizer.Form.NFD).replaceAll("[^\\p{ASCII}]", "");
//Chamando o filter
clienteAdapter.getFilter().filter(texto);
return false;
}
});
super.onCreateOptionsMenu(menu, inflater);
}
And inside the Adapter:
@Override
protected FilterResults performFiltering(CharSequence constraint) {
List<ClienteEntity> filteredList = new ArrayList<>();
if(constraint == null || constraint.length() == 0){
filteredList.addAll(clientesListaFull); //Quando não há nada digitado na pesquisa, mostramos a lista completa (padrão).
}else{
//Trasforma a CharSequence em uma String, coloca tudo minúsculo e remove espaços.
String filterPattern = constraint.toString().toLowerCase().trim();
for(ClienteEntity cliente : clientesListaFull){ //Percorre cliente por cliente da lista de clientes.
String nomeNoASCII;
nomeNoASCII = Normalizer.normalize(cliente.getName(), Normalizer.Form.NFD)
.replaceAll("[^\\p{ASCII}]", "");
if(nomeNoASCII.toLowerCase().contains(filterPattern)){ //Se a CharSequence digitada estiver contida no cliente.getName, adicionamos esse cliente ao resultado da busca.
filteredList.add(cliente);
}
}
}
FilterResults results = new FilterResults();
results.values = filteredList;
return results;
}
Desculpa sou iniciante ainda mas oq eu coloco no lugar de
searchTesta vermelho e
` text not being used– Welyson
I fixed, look dnv, in place of the searchT you put the query
– Woton Sampaio
There you put the text q whether it is modified
– Woton Sampaio
Gave error pq copied d d an aq project and I forgot to change that part before d put here kkkk, dscp there
– Woton Sampaio
@Welyson if the answer solved your problem, mark it as accepted so that others who have the same problem can also solve it
– Woton Sampaio
ok, but I’m having a problem the text is going through Adapter of an arraylist of objects, and I can not pass to the td q I put from "never used"
– Welyson
could help me?
– Welyson
@Welyson dude, I don’t quite understand your question, I think I’d better open another question with part of the code, it’s better for understanding
– Woton Sampaio
@Welyson n, calm, you speak on onQueryTextChange?
– Woton Sampaio
yes
String como eu passo meu texto aqui;
 aqui= Normalizer.normalize(query, Normalizer.Form.NFD).replaceAll("[^\\p{ASCII}]", "");
I try to pass but no go– Welyson
look this is my code https://answall.com/questions/237899/searchno-listview-n%C3%A3o-show-item-matching
– Welyson
@Welyson laughs mt agr because of the memes, but coming back to the case, you want to pass for the arraylist your text without accents, right?
– Woton Sampaio
I’ll modify the answer, look there
– Woton Sampaio
@Welyson see if that’s what you want
– Woton Sampaio
unfortunately it didn’t work, but you’re a pretty cool guy I’m going to give up this battle and try to create a favorite vlw system if you want to help me
– Welyson
@Welyson Sad...
– Woton Sampaio