2

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");
MBehtemam
  • 7,865
  • 15
  • 66
  • 108
Elnaz
  • 511
  • 5
  • 16
  • Use intent.putExtra. – Ankita Sep 19 '17 at 07:17
  • are you getting the intented data/query in this activity – Pranav Ashok Sep 19 '17 at 07:17
  • 3
    i believe ur problem is not how to getting string from intent but how to searching programmatically using search view check this answer sir https://stackoverflow.com/questions/14426769/how-to-change-android-searchview-text – huzain07 Sep 19 '17 at 07:21
  • 1
    Possible duplicate of [how to change android SearchView text](https://stackoverflow.com/questions/14426769/how-to-change-android-searchview-text) – MBehtemam Jun 17 '19 at 11:19

2 Answers2

5

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);
Community
  • 1
  • 1
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
0
//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.

RRTW
  • 3,160
  • 1
  • 35
  • 54