title: Set different default checked/unchecked on AlertDialog
body: <p>I have a program that will pass a HashMap(Let say groupIdBefore) to a new Activity,</p>
  
  <p>And in this Activity I will get some data from Database and stored it in HashMap (ListGroupId )</p>
  
  <p>Then,</p>
  
  <p>I want to create a checkbox alertDialog, this AlertDialog will shows some data from ListGroupId, then I want to compare ListGroupId and groupIdBefore, if value of ListGroupId is equal with groupIdBefore,</p>
  
  <p>Then (when the checkbox AlertDialog is shown) the checkbox is set Checked, otherwise the checkbox is left unchecked.</p>
  
  <p>Here are my code,</p>
  
  <pre><code>public void alertDialogBuilder() {
      // TODO Auto-generated method stub
      Log.d("Flag", "arrive at alertdialogBuilder");
      final String[] listGroupName = new String[mGroupList.size()];
      final String[] listGroupId = new String[mGroupList.size()];
      final boolean[] itemsChecked = new boolean[mGroupList.size()];
  
      final String[] groupIdBefore = new String[localGroupList.size()];
  
      // Get hashmap from previous Activity and convert to string
      for (int i = 0; i &lt; localGroupList.size(); i++) {
          groupIdBefore[i] = localGroupList.get(i).get("groupId");
      }
  
      // Convert all groupId and groupName produced by this activity (all
      // groups this User has)
      for (int i = 0; i &lt; mGroupList.size(); i++) {
          Dat[i] = mGroupList.get(i).get("groupName");
          listGroupId[i] = mGroupList.get(i).get("groupId");
  
          for (int j = 0; j &lt; localGroupList.size(); j++) {
              if (listGroupId[i].equals(groupIdBefore[j])) {
                  itemsChecked[i] = true;
              }
          }
  
      }
  
      AlertDialog.Builder builder = new AlertDialog.Builder(
              EditAnnouncement.this);
  
      builder.setTitle("Choose Your Group : ");
  
      builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
  
          @Override
          public void onClick(DialogInterface dialog, int which) {
              groupList.clear();
              stringList.clear();
              selectedGroups.setText("Post To : ");
  
              for (int i = 0; i &lt; listGroupName.length; i++) {
                  if (itemsChecked[i]) {
                      groupList.add(listGroupName[i]);
                      stringList.add(listGroupId[i]);
                      itemsChecked[i] = false;
                  }
                  Log.d("flag", "after for");
  
              }
              String string = "";
              for (int i = 0; i &lt; groupList.size(); i++) {
                  selectedGroups.setText("Post To : ");
                  string = string + " " + groupList.get(i);
  
              }
              selectedGroups.setText(selectedGroups.getText().toString()
                      + string);
          }
      });
      builder.setMultiChoiceItems(listGroupName, new boolean[] { false,
              false, false },
              new DialogInterface.OnMultiChoiceClickListener() {
  
                  @Override
                  public void onClick(DialogInterface dialog, int which,
                          boolean isChecked) {
                      itemsChecked[which] = isChecked;
                  }
              });
      builder.show();
      Log.d("flag", "bottom of alert dialog");
  }
  </code></pre>
  
  <p>But items with the same value is not checked,</p>
  
  <p>Can you please help me to solve this problem? I dont really understand how checkbox alertdialog really works</p>
  
  <p>Thank you in advance</p>