0
我有一個AutoCompleteTextView,它使用SimpleCursorAdapter爲輸入字段篩選電子郵件。我有它的工作,雖然有一些deprecated
命令,我不知道如何返工。具有SimpleCursorAdapter的AutoCompleteTextView用於未返回遊標實際值的聯繫人
我遇到的唯一問題是,當我從提供的列表中的值,我沒有收到電子郵件地址選擇,但是像下面這樣:
[email protected]
這裏是我的代碼:
final AutoCompleteTextView edt_Contact = (AutoCompleteTextView)findViewById(idTo);
ContentResolver cr = getContentResolver();
String[] projection={ContactsContract.CommonDataKinds.Email._ID,ContactsContract.CommonDataKinds.Email.ADDRESS};
Cursor cursor = cr.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, projection, null, null, null);
startManagingCursor(cursor);
String[] from = new String[] { ContactsContract.CommonDataKinds.Email.ADDRESS};
int[] to = new int[] { android.R.id.text1};
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, cursor, from, to);
adapter.setFilterQueryProvider(new FilterQueryProvider() {
public Cursor runQuery(CharSequence constraint) {
return getContentResolver().query(ContactsContract.CommonDataKinds.Email.CONTENT_URI,
new String[] {},
ContactsContract.CommonDataKinds.Email.ADDRESS + " LIKE '%" + constraint + "%'",
null, null);
}
});
edt_Contact.setAdapter(adapter);
有關如何獲得實際選定值以在選擇時填充AutoCompleteTextView的任何建議?
此外,如上所述,棄用的項目是startManagingCursor
和SimpleCursorAdapter
。