本文介紹了帶有聯系人的自動完成 TextView的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我需要顯示一個自動完成文本框,它基本上會加載聯系人電子郵件 ID.我已經嘗試使用自定義適配器,但文本框中沒有填充任何內容.完全沒有建議.任何解決方案都會非常有用.
i need to display an auto complete text box which will basically load the contacts e-mail ids. I have tried it using a custom adapter but nothing gets populated in the textbox. No suggestions at all. Any solutions will be very useful.
推薦答案
試試以下:
ArrayList<String> emailAddressCollection = new ArrayList<String>();
ContentResolver cr = getContentResolver();
Cursor emailCur = cr.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, null, null, null, null);
while (emailCur.moveToNext())
{
String email = emailCur.getString(emailCur.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
emailAddressCollection.add(email);
}
emailCur.close();
String[] emailAddresses = new String[emailAddressCollection.size()];
emailAddressCollection.toArray(emailAddresses);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, emailAddresses);
AutoCompleteTextView textView = (AutoCompleteTextView)findViewById(R.id.YOUR_TEXT_VIEW);
textView.setAdapter(adapter);
}
注意:不要忘記將 READ_CONTACTS
權限添加到您的 Manifest.xml:
Note: Don't forget to add the READ_CONTACTS
permission to your Manifest.xml:
<uses-permission android:name="android.permission.READ_CONTACTS" />
這篇關于帶有聯系人的自動完成 TextView的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!