下面的代碼是讓手機通訊錄..
class LoadContactsAyscn extends AsyncTask<Void, Void, ArrayList<AllContact>> {
ProgressDialog pd;
ArrayList<AllContact> contacts;
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
pd = ProgressDialog.show(getActivity(), "Loading Contacts",
"Please Wait");
}
@Override
protected ArrayList<AllContact> doInBackground(Void... params) {
// TODO Auto-generated method stub
ArrayList<AllContact> contacts = new ArrayList<AllContact>();
Cursor c = getActivity().getContentResolver().query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
null, null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " ASC");
while (c.moveToNext()) {
String contactName = c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
String phNumber = c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
AllContact allcontacts = new AllContact();
allcontacts.setName(contactName);
allcontacts.setNumber(phNumber);
contacts.add(allcontacts);
}
c.close();
return contacts;
}
@Override
protected void onPostExecute(ArrayList<AllContact> contacts) {
// TODO Auto-generated method stub
super.onPostExecute(contacts);
pd.cancel();
adapter = new MyCustomAdapter(getActivity(), R.layout.select_text_layout, contacts);
list.setAdapter(adapter);
}
}
請編輯問題的標題,你是問有關聯繫人,日曆沒有。 – Dario
你爲什麼要大寫'app'?這不是一個縮寫。 –
對不起,我沒有在標題中看到錯誤的字詞。 – MateusFMello