小编use*_*255的帖子

如何使用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>
Run Code Online (Sandbox Code Playgroud)

我的搜索活动在我的清单文件中定义,如此.

<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>
Run Code Online (Sandbox Code Playgroud)

现在我的问题是当我从我的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));  
          }  
      }  
Run Code Online (Sandbox Code Playgroud)

请帮忙,如何从我的MenuActivity调用搜索请求?

android

8
推荐指数
2
解决办法
8945
查看次数

标签 统计

android ×1