How to set searchview text in Android

3.3k views Asked by At

I try to find a method for setting text for SearchView but I can't find anything? does any one know any method for doing this ? for example something like this

 searchView.setText("blah blah");
2

There are 2 answers

0
AskNilesh On BEST ANSWER

try this use setQuery

setQuery(CharSequence query, boolean submit)

Sets a query string in the text field and optionally submits the query as well.

sample code

send title to other activity using intent

Intent intent=new Intent(this, OtherActivity.class);
intent.putExtra("TITLE", "NILESH");
startActivity(intent);

Retrive title in other activity like this

String str = getIntent().getStringExtra("TITLE");
searchView.setQuery(str, false);
0
RRTW On
//1st activity
Intent intent=new Intent(view.getContext(), 2ndActivity.class);
intent.putExtra("key", someValue);
startActivity(intent);


//2nd activity
String value="";
Intent intent=getIntent();
Bundle bundle=intent.getExtras();
if(bundle!=null)
{
  mealId=bundle.getString("key");
}

Since you had get value in 2nd activity, other things are simple.