【问题标题】:How to set searchview text in Android如何在 Android 中设置搜索视图文本
【发布时间】:2018-02-27 20:51:05
【问题描述】:
我试图找到一种为 SearchView 设置文本的方法,但我找不到任何东西?有人知道这样做的任何方法吗?例如这样的事情
searchView.setText("blah blah");
【问题讨论】:
标签:
android
searchview
android-search
【解决方案1】:
试试这个用法setQuery
setQuery(CharSequence query, boolean submit)
在文本字段中设置查询字符串,并可选择提交查询。
示例代码
使用意图将标题发送到其他活动
Intent intent=new Intent(this, OtherActivity.class);
intent.putExtra("TITLE", "NILESH");
startActivity(intent);
像这样在其他活动中检索标题
String str = getIntent().getStringExtra("TITLE");
searchView.setQuery(str, false);
【解决方案2】:
//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");
}
由于您在第二次活动中获得了价值,其他事情就很简单了。