android利用onSearchRequested()调用内部搜索ui组件

android利用onSearchRequested()调用内部搜索ui组件

By 王军, 2010年04月21日 1:29 上午

android自带内部搜索ui组件,在实际的activty中,要调用搜索组件,完成输入内容然后进行搜素处理,得到相应的数据到相应的activty中显示数据。

下面是搜素的截图:

image

 

主要实现代码:

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

       Button button1 = (Button) findViewById(R.id.button);

        button1.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                onSearchRequested();
            }
        });
    }
    @Override
    public boolean onSearchRequested() {

        Bundle appDataBundle = new Bundle();
        appDataBundle.putString("demo_key", "dddd");

        startSearch("搜索", false, appDataBundle, false);
        return true;
    }

重要配置:AndroidManifest.xml文件

<application android:icon="@drawable/icon" android:label="@string/app_name">
       <activity android:name=".SearchManager"
                 android:label="@string/app_name">
           <intent-filter>
               <action android:name="android.intent.action.MAIN" />
               <category android:name="android.intent.category.LAUNCHER" />
           </intent-filter>
           <meta-data android:name="android.app.default_searchable"
                      android:value=".ResultActivty" />
       </activity>
        <activity android:name=".ResultActivty"
                 android:label="@string/search_query_results">
           <intent-filter>
               <action android:name="android.intent.action.MAIN" />
               <category android:name="android.intent.category.SAMPLE_CODE" />
           </intent-filter>
           <intent-filter>
               <action android:name="android.intent.action.SEARCH" />
               <category android:name="android.intent.category.DEFAULT" />
           </intent-filter>
           <meta-data android:name="android.app.searchable"
                      android:resource="@xml/searchable" />
       </activity>

   </application>

searchable.xml文件:

<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
    android:label="@string/search_label"
    android:hint="@string/search_hint"
    android:searchMode="showSearchLabelAsBadge"
    android:voiceSearchMode="showVoiceSearchButton|launchRecognizer"
    android:voiceLanguageModel="free_form"
    android:voicePromptText="@string/search_invoke"
    android:searchSuggestAuthority="com.example.android.apis.SuggestionProvider"
    android:searchSuggestSelection=" ? "
/>

源代码:http://easymorse-android.googlecode.com/svn/trunk/android.searchmanager

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值