Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get the events of searchview in android

Tags:

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.

like image 999
andro-girl Avatar asked Apr 19 '11 08:04

andro-girl


People also ask

How to use SearchView in android?

SearchView widget can be implemented over ToolBar/ActionBar or inside a layout. SearchView is by default collapsible and set to be iconified using setIconifiedByDefault(true) method of SearchView class. For making search field visible, SearchView uses setIconifiedByDefault(false) method.

How to implement search functionality in android?

When you're ready to add search functionality to your application, Android helps you implement the user interface with either a search dialog that appears at the top of the activity window or a search widget that you can insert in your layout.

How do I add text in SearchView?

You can use setQuery() to change the text in the textbox. However, setQuery() method triggers the focus state of a search view, so a keyboard will show on the screen after this method has been invoked. To fix this problem, just call searchView.


1 Answers

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;     } } 
like image 193
HighFlyer Avatar answered Oct 03 '22 00:10

HighFlyer