关于在应用程序中删除联系人

时间:2016-03-10 17:28:16

标签: android

我想在按钮上单击列表中选择并显示特定联系人,按钮名为添加,然后单击要调用的函数onContactClick,这样当我单击按钮时,我的手机联系人会显示,我可以选择联系人并将其显示在列表视图中。我正在执行以下操作

ArrayList<Econtacts> econtacts;
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_third);
    etext=(EditText)findViewById(R.id.emtext);
   econtacts = new ArrayList<>();
   Uri CONTENT_URI = ContactsContract.Contacts.CONTENT_URI;
    ContentResolver cr = getContentResolver();
    Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,
            null, null, null, null);
    if (cur.getCount() > 0) {
        while (cur.moveToNext()) {
            id = cur.getString(
                    cur.getColumnIndex(ContactsContract.Contacts._ID));
            name = cur.getString(
                    cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
            if (Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
                phone = Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER)));          //Query phone here.  Covered next
            }

            econtacts.add(new Econtacts(phone, name, id));

        }
    }
    public void onContactsClick (View  view) {
    ArrayAdapter<Econtacts> adapter =new ArrayAdapter<Econtacts>(getApplicationContext(),R.layout.text,econtacts);
    list = (ListView) findViewById(R.id.contactList);
    list.setAdapter(adapter);
}

并且Econtacts类在这里

public class Econtacts {
private String _id;
private int _econtacts;
private String _ename;

public int get_econtacts() {
    return _econtacts;
}

public String get_id() {
    return _id;
}

public void set_id(String _id) {
    this._id = _id;
}

public void set_econtacts(int _econtacts) {
    this._econtacts = _econtacts;
}

public String get_ename() {
    return _ename;
}

public void set_ename(String _ename) {
    this._ename = _ename;
}

public Econtacts(int _econtacts,String _ename,String _id) {

    this._econtacts = _econtacts;
    this._ename=_ename;
    this._id=_id;} }

我做错了什么,因为每当我点击添加按钮时,应用程序停止的消息就会出现。请任何人指导我。谢谢提前

0 个答案:

没有答案