1

重複の可能性:
入力されたリストビューのすべての連絡先にチェックボックスをリンクするにはどうすればよいですか?

いま初心者中androidです。

電話の連絡先を取得しlistview てチェックボックスに入れ、ユーザーが複数の連絡先を選択して選択した連絡先を取得できるようにします。

そのためのものはありますかtutorial????

ありがとう

4

2 に答える 2

3

チェックボックスを使用してすべての連絡先を取得するコードは次のとおりです。

ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);

if (cur.getCount() > 0) {
  while (cur.moveToNext()) {
    String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
    String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
    if (Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
      // This inner cursor is for contacts that have multiple numbers.
      Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[] { id }, null);
      while (pCur.moveToNext()) {
        phoneContactList.add(name);
        Log.i("Contact List", name);
      }
      pCur.close();
    }
  }

  Collections.sort(phoneContactList);
  cnt = phoneContactList.size();

  listView.setAdapter(new ArrayAdapter<String>(this, R.drawable.multiple_contact_selector, phoneContactList));
  listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

}
cur.close();
于 2012-09-18T04:40:42.170 に答える
2

I think this can help you : Custom Android ListView to read phone contacts .

First of all check this

1) Add permission in the manifest file.

<uses-permission android:name="android.permission.READ_CONTACTS"/>
于 2012-09-18T04:28:10.613 に答える