我試圖實現搜索對話框,我無法顯示來自活動的搜索。如何使用onSearchRequested()調用搜索對話框()
我有我的清單文件中定義的主要活動,此活動向用戶顯示他們必須從中選擇的選項列表。其中一個選項是搜索選項。
<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>
我的搜索活動在我的清單文件中定義如此。
<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()沒有任何反應。
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調用搜索請求?
你能接受一些答案作爲「答案」嗎? – motiver 2013-01-22 23:43:06