如何从列表视图中禁用已选择的项目

时间:2014-07-31 14:28:21

标签: android xml email android-edittext android-contacts

您好我试图在我的电话簿中收到我的联系人的电子邮件并将其设置为edittext。我可以收到电子邮件,但即使我点击完成不同电子邮件的其他人,我也只能在电话簿上设置第一封电子邮件。我当我点击编辑文本然后从用户电子邮件中设置纠察队时,就会发生这种情况。

当我点击此按钮打开我的联系人列表

Button buttonPickContact = (Button) findViewById(R.id.contactact_us_btn);
        buttonPickContact.setOnClickListener(new Button.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
                intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
                startActivityForResult(intent, 1);
            }
        }); 

并使用此功能我尝试将电子邮件设置为edittext但每次只设置一封电子邮件

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);

        ContentResolver cr = getContentResolver();
        Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null,
                null, null, null);
        // if user got more then one person in his contact list
        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) {

                //  Log.d("NAMEEE:", name);
                //  System.out.println("name : " + name + ", ID : " + id);

                    // get email and type

                    Cursor emailCur = cr.query(
                            ContactsContract.CommonDataKinds.Email.CONTENT_URI,
                            null,
                            ContactsContract.CommonDataKinds.Email.CONTACT_ID
                                    + " = ?", new String[] { id }, null);
                    while (emailCur.moveToNext()) {
                        // This would allow you get several email addresses
                        // if the email addresses were stored in an array
                        String email = emailCur
                                .getString(emailCur
                                        .getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
                        String emailType = emailCur
                                .getString(emailCur
                                        .getColumnIndex(ContactsContract.CommonDataKinds.Email.TYPE));

                        contactNumber = (EditText) findViewById(R.id.waitingToAdd_edittext);
                        // contactName.setText(name);
                        contactNumber.setText(email);

                        System.out.println("Email " + email + " Email Type : "
                                + emailType);
                    }
                    emailCur.close();

                }
            }
        }

    }

如何设置电子邮件我选择的不仅仅是一个时间

0 个答案:

没有答案