Sasi
Sasi

Reputation: 465

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

Upvotes: 4

Views: 2487

Answers (2)

Paresh
Paresh

Reputation: 6857

First thing first..

onQueryTextChange() will not be fired until you are not entering any text

, Instead what you can do is, make a call to search api with empty query param and get results...

Once text changes - You can use conditions given in other answers!! even your condition will work too.

Upvotes: 1

Pratik Dasa
Pratik Dasa

Reputation: 7439

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

if(TextUtils.isEmpty(newText)){
     // Do your stuff here.
} 

Upvotes: 2

Related Questions