如何添加Android通讯录到一个列表视图与复选框 [英] How to add Android Contacts into a listview with a check box

查看:116
本文介绍了如何添加Android通讯录到一个列表视图与复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  <一href=\"http://stackoverflow.com/questions/10544821/how-do-i-link-a-checkbox-for-every-contact-in-populated-listview\">How我做链接复选框人口中的每一个列表视图接触?

我M在机器人初学者。

我想拿到手机的联系人,然后把它们放在一个列表视图
  一个复选框,以便用户可以选择一个以上的接触,然后
  获得选定的联系人。

i want to get the phone contacts and then put them into a listview with a checkbox so that user can select more then one contact and then get the selected contacts.

有任何教程为????

感谢

推荐答案

这里是code得到使用复选框所有联系人:

here is the code to get all contacts with checkbox :

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();

这篇关于如何添加Android通讯录到一个列表视图与复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆