简体   繁体   English

如何在Android的edittext中添加搜索功能

[英]how to add search functionality in edittext in Android

I want to add search functionality in android .我想在 android 中添加搜索功能。 Whenever I enter the any letter all contacts started with this letter will be showed in an listview which is as follows :每当我输入任何字母时,所有以此字母开头的联系人都将显示在列表视图中,如下所示:

在此处输入图片说明

How can I search this entered letter in contact list ?如何在联系人列表中搜索此输入的字母? How can I show search result in an listview as in picture ?如何在列表视图中显示搜索结果,如图所示?

I know this can be done AutoCompleteTextView But I can not search over contacts .我知道这可以做到 AutoCompleteTextView 但我无法搜索联系人。 How can I do this ?我怎样才能做到这一点 ?

Load all the contacts in array list or string array and then use AutoCompleteTextView for adding search functionallity加载数组列表或字符串数​​组中的所有联系人,然后使用AutoCompleteTextView添加搜索功能

Gett all contacts like this as expalined here获取所有这样的联系人,如解释here

public ArrayList<PhoneContactInfo> getAllPhoneContacts() {

    Log.d("START","Getting all Contacts");
    ArrayList<PhoneContactInfo> arrContacts = new ArrayList<PhoneContactInfo>();
    PhoneContactInfo phoneContactInfo=null;     
    Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
    Cursor cursor = context.getContentResolver().query(uri, new String[] {ContactsContract.CommonDataKinds.Phone.NUMBER,ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,ContactsContract.CommonDataKinds.Phone._ID}, null, null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " ASC");
    cursor.moveToFirst();
    while (cursor.isAfterLast() == false)
    {
        String contactNumber= cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));  
        String contactName =  cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
        int phoneContactID = cursor.getInt(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone._ID));


        phoneContactInfo = new PhoneContactInfo();
        phoneContactInfo.setPhoneContactID(phoneContactID);             
        phoneContactInfo.setContactName(contactName);                   
        phoneContactInfo.setContactNumber(contactNumber); 
        if (phoneContactInfo != null)
        {
            arrContacts.add(phoneContactInfo);
        }
        phoneContactInfo = null; 
        cursor.moveToNext();
    }       
    cursor.close();
    cursor = null;
    Log.d("END","Got all Contacts");
    return arrContacts;
}

您可以使用 AutoCompleteTextView 获取有用的链接: http : //www.javatpoint.com/android-autocompletetextview-example

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 EditText 为 android 应用程序的回收器视图提供搜索功能? - How to have search functionality using EditText for recycler view for android app? 如何为安卓应用添加搜索功能? - How to add search functionality to android app? 在Android中将搜索功能添加到ListView - Add Search Functionality to ListView in android 如何在 android kotlin 中为 cardview recyclerview 添加搜索功能? - How to add search functionality for cardview recyclerview in android kotlin? 如何使用Volley库在android recyclerView中添加搜索功能 - how to add Search functionality in android recyclerView using Volley library 如何在android的gridview中添加搜索功能? - How do i add search functionality in gridview in android? 如何在 android studio 的 firestore 中添加全文搜索功能? - How to add full text search functionality in firestore in android studio? 在 xamarin android 中使用 edittext 即时搜索列表视图功能 - instant Search functionality to listview using edittext in xamarin android 如何在 Listview 中添加搜索功能? - How to add search functionality into Listview? 如何在ListView中添加搜索功能 - How To Add Search Functionality in ListView
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM