Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android how to search in empty query

I have an search view, below the search view contain edittext. i can check based on search view query and edittext content. Event the query is empty i need to search. Is this is

I have tried this but doesn't work

 searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
    @Override
    public boolean onQueryTextSubmit(String query) {
        Log.i("MyApp", searchView.getQuery().toString());
        consultarListaParadas(searchView.getQuery().toString());
        getActivity().runOnUiThread(new Runnable() {
            public void run() {
                adaptadorListaParadasBus.setListaParadas(listaParadas);
                adaptadorListaParadasBus.notifyDataSetChanged();
            }
        });

        return true;
    }

    @Override
    public boolean onQueryTextChange(String newText) {

        if(newText.equals("")){
            this.onQueryTextSubmit("");
        }
        return true;
    }
}); 
like image 814
Sasi Avatar asked Sep 21 '25 04:09

Sasi


1 Answers

Try with below condition inside onQueryTextChange() method, like below

if(TextUtils.isEmpty(newText)){
     // Do your stuff here.
} 
like image 79
Pratik Dasa Avatar answered Sep 22 '25 19:09

Pratik Dasa