不能添加重复的Contact到RecipientBox中
不能添加重复的Contact到RecipientBox中
在开始添加的操作时,判断是否已在RecipientBox中,如果已经在返回值为null的TextView。
再根据TextView判断是否null,如果非null添加到RecipientBox中,如果null弹出Toast提示。
private TextView getRecipientItem(TxrjContact contact) {
if(!mRecipients.contains(contact)) {
mRecipients.add(contact);
return getRecipientItem(contact, null);
} else {
return null;
}
}
private TextView getRecipientItem(String number) {
if(!mNumbers.contains(number)) {
mNumbers.add(number);
return getRecipientItem(null, number);
} else {
return null;
}
}
private void addRecipientItem(TextView item) {
if(item != null) {
mViewGroup.addView(item, mViewGroup.getChildCount() - 2);
mRecipientInput.setText("");
} else {
Toast.makeText(mContext, "can't add duplicate contact or phone number.", Toast.LENGTH_SHORT).show();
}
}
在onCreate方法中开头就定义mRecipients和mNumbers
mRecipients = new ArrayList<TxrjContact>();
mNumbers = new ArrayList<String>();