如何调用使用onSearchRequested搜索对话框() [英] How do I invoke the search dialog using onSearchRequested()
问题描述
我想实现的搜索对话框,我无法显示从活动搜索。
I'm trying to implement the search dialog and I am unable to display the search from an Activity.
我在清单文件我的主要活动定义,本次活动展示了用户,他们有可供选择的选项列表。其中一个选项是一个搜索选项。
I have my main activity defined in my manifest file, this activity shows the user a list of options they have to choose from. One of the options is a Search option.
<activity
android:name=".MenuListActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
我的搜索活动在我的清单文件中定义如下。
My Search activity is defined in my manifest file like so.
<activity android:name=".SearchActivity"
android:launchMode="singleTop"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="@xml/searchable"/>
</activity>
现在我的问题是,当我从我的MenuListActivity什么也没发生调用onSearchRequested()。
Now my problem is when I call the onSearchRequested() from my MenuListActivity nothing happens.
public void onItemClick(AdapterView<?> parent, View itemClicked, int position, long id) {
String strText = items[position];
if (strText.equalsIgnoreCase(getResources().getString(R.string.menu_item_browse))) {
startActivity(new Intent(MenuListActivity.this, WSMobileActivity.class));
} else if (strText.equalsIgnoreCase(getResources().getString(R.string.menu_item_search))) {
// If i call it like this it doesn't work, nothing happens
onSearchRequested();
} else if (strText.equalsIgnoreCase(getResources().getString(R.string.menu_item_locator))) {
startActivity(new Intent(MenuListActivity.this, StoreLocatorActivity.class));
}
}
请帮忙,我怎么调用从我MenuActivity搜索请求?
Please help, how do I invoke the search request from my MenuActivity?
推荐答案
你检查你的RES / XML / searchable.xml?
did you check your res/xml/searchable.xml?
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:hint="@string/search_hint"
android:label="@string/search_label">
</searchable>
搜索对话框不显示的时候你已经很难codeD字符串提示和标签。他们必须@string资源。
Search dialog doesn't show up when you have hard coded strings for hint and label. They have to be @string resources.
此外,没有必要打电话或在您的通话活动覆盖onSearchRequested()方法,除非你想从像一个按钮或列表项的UI部件之一来使用搜索。
Also, there is no need to call or override the onSearchRequested() method in your calling activity unless you want to invoke search from one of your UI widgets like a Button or a ListItem.
这篇关于如何调用使用onSearchRequested搜索对话框()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!