首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >向我的searchable.xml添加约束

向我的searchable.xml添加约束
EN

Stack Overflow用户
提问于 2015-12-29 13:09:05
回答 1查看 88关注 0票数 0

我使用以下xml文件为我的SearchView实现自动建议:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="@string/find_contact"
android:hint="@string/find_contact"
android:gravity="center"
android:includeInGlobalSearch="true"
android:queryAfterZeroResults="true"
android:searchMode="queryRewriteFromText"
android:searchSettingsDescription="@string/find_contact"
android:searchSuggestAuthority="com.android.contacts"
android:searchSuggestIntentAction="android.provider.Contacts.SEARCH_SUGGESTION_CLICKED"
android:searchSuggestIntentData="content://com.android.contacts/contacts/lookup" >

<!-- allow green action key for search-bar and per-suggestion clicks -->
<actionkey
    android:keycode="KEYCODE_CALL"
    android:queryActionMsg="call"
    android:suggestActionMsg="call" />

</searchable>

问题是,除了建议有效的联系人外,它还在联系人和其他“假”联系人中提供了电子邮件in的建议。

我想添加一个约束,只对有效的电话联系人提供建议,即有电话号码的联系人。

如何实现这一点?

EN

回答 1

Stack Overflow用户

发布于 2015-12-29 14:04:15

在我看来,唯一的方法是扩展ContentProvider,用于查询所需实体的ContactProvider,并将其在searchable.xml中分配为searchSuggestAuthority。

http://developer.android.com/guide/topics/providers/content-provider-creating.html

ContactsContract.Contacts类还包含HAS_PHONE_NUMBER列,因此您可以通过对该字段进行以下过滤来查询联系人提供程序:

代码语言:javascript
复制
context.getContentResolver().query(ContactsContract.Contact.CONTENT_LOOKUP_URI, new String[]{ContactsContract.Contact._ID}, ContactsContract.Contact.HAS_PHONE_NUMBER + "=?", new String[]{"1"}, null), true);

我以前没有检查过代码,但我希望我能给出一些好的提示;)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34511778

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档