在searchview联系人建议中显示姓名,号码和联系方式

时间:2017-11-03 15:45:55

标签: android android-contacts android-search

当用户在SearchView中键入联系人姓名时,我使用以下可搜索的xml进行自动提示选项。

<?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" />

我正在使用 android.support.v7.widget.SearchView 。现在,当我输入我正在搜索的联系人的姓名时,只有姓名和联系人的图像(如果存在)显示在建议列表中。如何在建议列表中为每个建议显示联系电话号码以及联系方式(工作,家庭,移动电话等)?

1 个答案:

答案 0 :(得分:0)

您应该避免使用android:searchSuggestIntentData进行搜索,并自行执行,然后您可以控制查询本身以及建议适配器。

参见官方教程:

  1. https://developer.android.com/guide/topics/search/index.html
  2. https://developer.android.com/guide/topics/search/adding-custom-suggestions.html
相关问题