Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to call onSearchRequested when pressing magnifying glass

Tags:

android

search

I'm using a searchView and try to pass some data when someone invokes a search. So i overrode the onSearchReqested method. The problem is, this method isn't called when someone types in the SearchView and presses the magnifying glass on the keyboard. Instead the result activity is started.

How can i call the onSearchRequested method prior starting the result activity when someone presses the magnifying glass.

i tried this two but it didnt work.

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.FLAG_EDITOR_ACTION) {
        onSearchRequested();
        return false;
    }
    return false;
}

adding a listener to the searchview didn't work either

searchView.setOnSearchClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        onSearchRequested();

    }
});

Thanks in advance for the help.

like image 877
Cheetah Avatar asked Sep 27 '12 10:09

Cheetah


1 Answers

setOnQueryTextListerner finally worked

searchView.setOnQueryTextListener(new OnQueryTextListener() {

    @Override
    public boolean onQueryTextSubmit(String query) {
        onSearchRequested();
        return false;
    }

    @Override
    public boolean onQueryTextChange(String newText) {
        // TODO Auto-generated method stub
        return false;
    }
});
like image 93
Cheetah Avatar answered Sep 30 '22 21:09

Cheetah