我想在android中添加搜索功能。每當我進入任何一個字母的所有聯繫人開始與這封信將在列表視圖來顯示這是如下:如何在Android的edittext中添加搜索功能
如何搜索這個進入聯繫人列表中的信?如何在列表視圖中顯示搜索結果?
我知道這可以完成AutoCompleteTextView但我無法搜索聯繫人。我怎樣才能做到這一點 ?
我想在android中添加搜索功能。每當我進入任何一個字母的所有聯繫人開始與這封信將在列表視圖來顯示這是如下:如何在Android的edittext中添加搜索功能
如何搜索這個進入聯繫人列表中的信?如何在列表視圖中顯示搜索結果?
我知道這可以完成AutoCompleteTextView但我無法搜索聯繫人。我怎樣才能做到這一點 ?
加載所有的數組列表或字符串數組中的聯繫人,然後使用AutoCompleteTextView添加搜索functionallity
GETT這樣所有聯繫人爲expalined 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;
}
如何加載數組列表中的所有聯繫人? –
檢查更新回答@ osimerpothe –
您可以使用AutoCompleteTextView 有幫助的鏈接:http://www.javatpoint.com/android-autocompletetextview-example
我如何搜索聯繫人?請舉一個例子。 –
舉例:http://androidexample.com/Show_Phone_Contacts_In_AutoComplete_Suggestions_-_Android_Example/index.php?view=article_discription&aid=106&aaid=128 –
http://stackoverflow.com/questions/14663725/list-view-filter-android – 1615903
你在問什麼叫'AutoC ompleteTextView' –
這取決於.... SearchView可用於Actionbar/Toolbar。至於簡單的EditText,您可以使用@ 1615903答案,Frank的AutoCompleteTextView,或者如果查詢需要來自服務器,則可以使用addTextChangedListener在API上進行搜索。 –