删除现有的Recipient再重新添加选中的Contacts

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if(requestCode == TxrjConstant.REQUEST_ADD_CONTACT && resultCode == RESULT_OK) {
        ArrayList<TxrjContact> extraContacts = data
                .getParcelableArrayListExtra(TxrjConstant.EXTRA_CONTACT_LIST);
        removeAllRecipientItems();
        mRecipients.clear();
        for (TxrjContact contact : extraContacts) {
            addRecipientItem(getRecipientItem(contact));
        }
    }
}

private void removeAllRecipientItems() {
    int count = mViewGroup.getChildCount();
    View view = null;
    TxrjContact contact = null;
    List<View> items = new ArrayList<View>();
    for (int i = 0; i < count - 2; i++) {
        view = mViewGroup.getChildAt(i);
        contact = (TxrjContact) view.getTag(R.id.tag_contact);
        if ((view instanceof TextView) && (contact != null)
                && mRecipients.contains(contact)) {
            items.add(view);
        }
    }
    for (View item : items) {
        mViewGroup.removeView(item);
    }
}

posted on 2013-07-14 10:30  勤修  阅读(258)  评论(0编辑  收藏  举报

导航