how to get the events of searchview in android

0

Issue

I’m using a search view in my application. Now i just want to get the text typed in the SearchView text box and display it on another textview. If i typed the text and click a button i can do the same. But i don’t want to use any extra buttons. I just want to display the result when i am pressing enter key.

Solution

Try to use setOnQueryTextListener of SearchView

new SearchView.OnQueryTextListener() {
    @Override
    public boolean onQueryTextChange(String newText) {
        // your text view here
        textView.setText(newText);
        return true;
    }

    @Override
    public boolean onQueryTextSubmit(String query) {
        textView.setText(query);
        return true;
    }
}

Answered By – HighFlyer

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More