Android通讯录开发之删除功能的实现方法

2019-12-10 20:12:50王旭

   }
  });
  dialog.show();
 }

 


下面是删除操作:
这里只关注实现删除的脉路,其中有些代码是业务逻辑需要可以稍微看一下就可以了
复制代码
 // 删除选中的联系人
 public void deleteContacts() {
  DialogHelp.getInstance().showHttpDialog(this, R.string.wait_for_while,
    getString(R.string.deleting_contact));
  new Thread() {
   @Override
   public void run() {
    ArrayList<Contact> deleteContacts = new ArrayList<Contact>();
    for (Contact contact : contactList) {
     boolean isselected = map_NumberSelected
       .get(contact.getId());
     if (isselected) {
      for (RawContact rawContact : rawList) {
       if (contact.getUserId() == rawContact.getUserId()) { // 是同一个id
        if (contact.getNumber() == rawContact
          .getPhone1()) {
         rawContact.setPhone1(null);
        } else if (contact.getNumber() == rawContact
          .getPhone2()) {
         rawContact.setPhone2(null);
        } else if (contact.getNumber() == rawContact
          .getTelephone()) {
         rawContact.setTelephone(null);
        }
        if ((rawContact.getPhone1() == null || ""
          .equals(rawContact.getPhone1()))
          && (rawContact.getPhone2() == null || ""
            .equals(rawContact.getPhone2()))
          && (rawContact.getTelephone() == null || ""
            .equals(rawContact
              .getTelephone()))) {
         MyDataBase.deleteContact(