如何在Android中设置searchview文本

问题描述 投票:1回答:2

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

 searchView.setText("blah blah");
android searchview android-search
2个回答
4
投票

试试这个使用setQuery

setQuery(CharSequence query, boolean submit)

在文本字段中设置查询字符串,并可选择提交查询。

示例代码

使用intent将标题发送到另一个活动

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

在此类其他活动中检索标题

String str = getIntent().getStringExtra("TITLE");
searchView.setQuery(str, false);

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");
}

既然你在第二项活动中获得了价值,那么其他事情就很简单。

© www.soinside.com 2019 - 2024. All rights reserved.