zoukankan      html  css  js  c++  java
  • Android开发——Android搜索框架(二)

    上一篇:Android开发——Android搜索框架(一) 距离上一篇文章有段时间了,唉。

    接着上一篇文章,现在说说如何在搜索的时候弹出搜索历史提示。

    1.创建搜索建议提供者

    Android已经为我们创建了一个默认的,我们只需要继承 SearchRecentSuggestionProvider 就稍做修改就可以了。

    见代码:

       1: import android.content.SearchRecentSuggestionsProvider;
       2:  
       3: /**
       4:  * 搜索提示
       5:  * 
       6:  * @author Hanguo
       7:  * http://t.sina.com.cn/halzhang
       8:  * @version 2011-1-5上午11:51:39
       9:  */
      10: public class SearchSuggestionsProvider extends SearchRecentSuggestionsProvider {
      11:     //记住这个哦
      12:     public final static String AUTHORITY = "searchprovider";
      13:  
      14:     public final static int MODE = DATABASE_MODE_QUERIES;
      15:  
      16:     public SearchSuggestionsProvider() {
      17:         setupSuggestions(AUTHORITY, MODE);
      18:     }
      19: }

    2.配置searchable.xml

       1: <?xml version="1.0" encoding="utf-8"?>
       2: <searchable xmlns:android="http://schemas.android.com/apk/res/android"
       3:     android:label="@string/search_label" 
       4:     android:hint="@string/search_hint"
       5:     android:searchSettingsDescription="@string/search_settings_description"
       6:     android:searchSuggestAuthority="searchprovider"
       7:     android:searchSuggestIntentAction="android.intent.action.SEARCH"
       8:     android:searchSuggestThreshold="1"
       9:     android:includeInGlobalSearch="true"
      10:     android:searchSuggestSelection=" ?"
      11:     >
      12: </searchable>
    参数说明:
    android:searchSuggestAuthorith
    此属性的值就是SearchSuggestAuthorith中的AUTHORITH了。
    android:searchSuggestIntentAction
    此属性定义了当我们选中搜索提示的内容时发生的目的动作。
    android:searchSuggestThreshold
    此属性定义了至少输入几个字符时才会弹出提示
    android:includeInGlobalSearch
    是否将内容加入android的全局搜索。true,加入。
    android:searchSuggestSelection
    定义搜索时参数的占位符
     
    PS:配置参数不止这些,可以自己看看android的参考手册。
     
    3.配置AndroidManifest.xml
       1: <provider android:name=".SearchSuggestionsProvider" android:authorities="searchprovider" />
     
    注意authorities的属性值哦。o(∩_∩)o

    如有问题欢迎邮件交流。

    转载请注明出处。

    -----------------end-----------------

  • 相关阅读:
    php 多进程
    关于TP的RBAC的使用
    谈谈自己对于Auth2.0的见解
    php 写队列
    关于thinkphp中Hook钩子的解析
    JS的闭包
    单链表的查找和取值-1
    shell输入输出重定向
    转-Visual Studio控制台程序输出窗口一闪而过的解决方法
    linux下如何调用不同目录下的.h 库文件
  • 原文地址:https://www.cnblogs.com/halzhang/p/1938752.html
Copyright © 2011-2022 走看看