title: Android checkbox dialog (easy)
body: <p>I have a dialog with checkboxes, and I was trying to do different things when options are selected and when <kbd>OK</kbd> is pressed.</p>
  
  <p>I thought I knew what I was doing after reading some tutorials, but when I press <kbd>OK</kbd> it just toasts "Everything" even if it isn't checked. So it seems that my <code>if</code> statements are not working correctly, but I don't know why.</p>
  
  <p>What am I doing wrong and how do I fix it?</p>
  
  <pre><code>    final CharSequence[] items = {"Item 1", "Item 2", "Item 3"};
      final boolean[] states = {false, false, false};
      AlertDialog.Builder builder = new AlertDialog.Builder(this);
      builder.setTitle("What would you like to do?");
  
      builder.setMultiChoiceItems(items, states, new DialogInterface.OnMultiChoiceClickListener(){
          public void onClick(DialogInterface dialogInterface, int item, boolean state) {
          }
      });
  
      builder.setPositiveButton("Okay", new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int id) {
              SparseBooleanArray CheCked = ((AlertDialog)dialog).getListView().getCheckedItemPositions();
              if(CheCked.get(CheCked.keyAt(0)) == true){
                  Toast.makeText(Backup.this, "Item 1", Toast.LENGTH_SHORT).show();
              }
              if(CheCked.get(CheCked.keyAt(1)) == true){
                  Toast.makeText(Backup.this, "Item 2", Toast.LENGTH_SHORT).show();
              }
              if(CheCked.get(CheCked.keyAt(2)) == true){
                  Toast.makeText(Backup.this, "Item 3", Toast.LENGTH_SHORT).show();
              }
          }
      });
  
      builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int id) {
               dialog.cancel();
          }
      });
  
      builder.create().show();
  }
  </code></pre>