我使用以下xml文件为我的SearchView实现自动建议:
<?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的建议。
我想添加一个约束,只对有效的电话联系人提供建议,即有电话号码的联系人。
如何实现这一点?
发布于 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列,因此您可以通过对该字段进行以下过滤来查询联系人提供程序:
context.getContentResolver().query(ContactsContract.Contact.CONTENT_LOOKUP_URI, new String[]{ContactsContract.Contact._ID}, ContactsContract.Contact.HAS_PHONE_NUMBER + "=?", new String[]{"1"}, null), true);我以前没有检查过代码,但我希望我能给出一些好的提示;)
https://stackoverflow.com/questions/34511778
复制相似问题