Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get input from searchview to textview

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());
like image 614
Theresa Gamit Avatar asked Dec 20 '13 21:12

Theresa Gamit


People also ask

How do I get text from SearchView?

To get text of SearchView , use searchView. getQuery() .

How to work with 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 Search data in Android using SearchView?

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.

How to add SearchView in Android studio?

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.


1 Answers

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)

like image 167
gaurav5430 Avatar answered Oct 16 '22 18:10

gaurav5430