Is there another way to get the input of searchview and put it into textview? It seems that the getText() and setText() method are not applicable to searchview.
Or
Is there a way to transfer the input from EditText to Searchview?
Please help me to look for necessary resources/codes/method about the above question. Thank you. Here is my code:
public boolean onQueryTextChange(String newText) {
// TODO Auto-generated method stub
showResults(newText);
return false;
}
@Override
public boolean onQueryTextSubmit(String query) {
// TODO Auto-generated method stub
tvInput = (TextView) findViewById (R.id.tvInput);
showResults(query);
// searchView.getQuery().toString();
tvInput.setText(searchView.getQuery().toString());
return false;
}
I also do it in other way. Here:
tvInput = (TextView) findViewById (R.id.tvInput);
tvInput.setText(searchView.getQuery());
To get text of SearchView , use searchView. getQuery() .
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.
Search View widget is used to provide a search interface to user so that the user can enter his search query and submit a request to search provider and get a list of query suggestions or results. It consist of Relative Layout with ListView in it from which data is to be search.
To add a SearchView widget to the app bar, create a file named res/menu/options_menu. xml in your project and add the following code to the file. This code defines how to create the search item, such as the icon to use and the title of the item.
for searchView to editText
editText.setText(searchView.getQuery());
for editText to SearchView
searchView.setQuery(editText.getText(),false);
http://developer.android.com/reference/android/widget/SearchView.html#getQuery()
http://developer.android.com/reference/android/widget/SearchView.html#setQuery(java.lang.CharSequence,boolean)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With