android:获取搜索建议点击项目的文本 [英] android: get text of a search suggestion clicked item
问题描述
我使用的是官方 Android 示例代码 SearchableDictionary,这为我们提供了一个搜索界面,您可以在其中搜索一个词,当用户键入时,建议会显示在下拉列表视图中.
I am using the officical Android sample code SearchableDictionary, that gives us a search interface, where you can search for a word and while the user types, suggestions are displayed in a dropdown listview.
点击搜索建议后,会向您的可搜索活动发送一个 Intent.此 Intent 的 Action 字段通过可搜索的 XML 进行描述,如下所示:
When a search suggestion is clicked, an Intent is sent to your searchable activity. The Action field of this Intent is described though your searchable XML like this:
<searchable
...
android:searchSuggestIntentAction = "android.intent.action.VIEW">
然后在可搜索的活动中:
and then in the searchable activity:
Intent intent = getIntent();
if (Intent.ACTION_VIEW.equals(intent.getAction()) {
//a suggestion was clicked... do something about it...
Intent myIntent = new Intent(this, NewActivity.class);
myIntent.setData(intent.getData());
startActivity(myIntent);
finish();
}
我的问题是我的 NEWACTIVITY 需要一个 id 来显示相关数据.这个 id 我可以通过获取被点击的项目的文本来获得(就像我们通过使用 getItemAtPosition(pos);
获得的)[一个字符串值].我如何得到它?
my problem is that my NEWACTIVITY requires an id to display the relevant data. this id i can get by getting the text of the item that was clicked (like we get by using getItemAtPosition(pos);
) [a string value]. How do i get it?
推荐答案
我做到了.
Cursor cursor = managedQuery(intent.getData(), null, null, null, null);
cursor.moveToFirst();
String y = cursor.getString(1).trim();
final int x = Integer.valueOf(y) - 1;
myIntent.putExtra("id", y);
这篇关于android:获取搜索建议点击项目的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!