如何在 Android 中设置搜索视图文本

How to set searchview text in Android

我试图找到一种为 SearchView 设置文本的方法,但找不到任何东西?有谁知道这样做的任何方法吗?例如像这样的

 searchView.setText("blah blah");

尝试使用 setQuery

setQuery(CharSequence query, boolean submit)

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

示例代码

使用 intent

将标题发送给其他 activity
Intent intent=new Intent(this, OtherActivity.class);
intent.putExtra("TITLE", "NILESH");
startActivity(intent);

像这样在其他activity中检索标题

String str = getIntent().getStringExtra("TITLE");
searchView.setQuery(str, false);
//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");
}

因为你在第二个 activity 中获得了价值,其他事情就简单了。