11

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());
2
  • are you adding the searchview on show of options menu?
    – gaurav5430
    Dec 20, 2013 at 22:46
  • if you need to set it inside onQueryTextSubmit, you can directly use the query parameter that is passed in.
    – gaurav5430
    Dec 20, 2013 at 23:00

1 Answer 1

20

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)

5
  • Hi Im trying your searchview to textview instead of editText. But It still doesnt get input from searchview. Dec 20, 2013 at 22:37
  • can you edit your question and post some code, also, is it returning null always or sometimes?
    – gaurav5430
    Dec 20, 2013 at 22:41
  • what does the showResults method do, can you try getting the query value before calling showResults()
    – gaurav5430
    Dec 20, 2013 at 22:43
  • Actually, it's working for invalid input only and not working for the words that are inside the database. Dec 20, 2013 at 22:51
  • Yeah, its working even in after and before showResults() for invalid input only. What do you think is the problem. But still.. Thank you.. :)) Dec 20, 2013 at 22:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.