title: Android managing items on AlertDialog
body: <p>I have this situation.</p>
  
  <p>On my layout I have 3 buttons and one radiogroup with two radiobuttons.
  The user must press <code>button1</code>, <code>button2</code>, pick one of the radiobuttons and after that, it will press <code>button3</code> and a query to a database will be performed.</p>
  
  <p>After pressing <code>button1</code>, a query will be performed and the result will be shown on an MultipleChoiceItems AlertDialog.</p>
  
  <p>I have some questions.</p>
  
  <p><strong>MultipleChoiceItems</strong></p>
  
  <p>I have three problems with this AlertDialog.</p>
  
  <p>First:
  The query result is shown on my AlertDialog but if I press any of the items no checkmark is placed on the checkbox. I can see in my toast message that the items is being checked.</p>
  
  <p>Second:
  The query is perform to the database but can I add one element that is not returned by the query?
  Imagine the AlertDialog, after the query, shows <code>One</code>,<code>Two</code>,<code>Three</code>. I want to add one more item. Something like <code>This was not returned by the query</code>,<code>One</code>,<code>Two</code>,<code>Three</code>.</p>
  
  <p>Third:</p>
  
  <p><code>public AlertDialog.Builder setMultiChoiceItems (Cursor cursor, String isCheckedColumn, String labelColumn, DialogInterface.OnMultiChoiceClickListener listener)</code> second parameter is to set the items checked or unchecked. My database does not have this column so I've passed one column that I know it is always different than zero. Is there a way to bypass this?</p>
  
  <p>This is my code:</p>
  
  <pre><code>public class MyClass extends ListActivity implements OnClickListener, OnCheckedChangeListener {
      Database db = new Database(this);
      int order;
      boolean groupCheck = false;
      boolean orderCheck = false;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          // TODO Auto-generated method stub
          super.onCreate(savedInstanceState);
          setContentView(R.layout.n);
  
          Button proc = (Button) findViewById(R.id.procButtonProc);
          proc.setOnClickListener(this);
          Button pickGroup = (Button) findViewById(R.id.procButtonGroup);
          pickGroup.setOnClickListener(this);
          RadioGroup pickOrder = (RadioGroup) findViewById(R.id.procRadioOrder);
          pickOrder.setOnCheckedChangeListener(this);
      }
  
      @Override
      public void onClick(View v) {
  
          if (v.getId() == R.id.procButtonGroup) {
  
              db.open();
              final Cursor query = db.getData(0, 0, null);
              AlertDialog.Builder pickGroup = new AlertDialog.Builder(this);
              pickGroup.setTitle(getString(R.string.procGroupTitle));
  
              pickGroup.setMultiChoiceItems(query, "GROUP_NAME", "GROUP_NAME", new DialogInterface.OnMultiChoiceClickListener() {
  
                  @Override
                  public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                      // TODO Auto-generated method stub
  
                      if (isChecked) {
                          query.moveToPosition(which);
                          String str = query.getString(1).toString();
                          Toast.makeText(MyClass.this, "You have selected " + str, Toast.LENGTH_LONG).show();
                          // ListView list = ((AlertDialog) dialog).getListView();
                          // list.setItemChecked(which, true);
  
                      }
                  }
              });
  
              pickGroup.setPositiveButton("OK", new DialogInterface.OnClickListener() {
  
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                      // TODO Auto-generated method stub
                  }
              });
  
              pickGroup.show();
              db.close();
  
          } 
  
          if (v.getId() == R.id.procButtonProc) {
  
              if (orderCheck == true &amp;&amp; groupCheck == true) {
                  // Based on the conditions, perform query on the database
  
              } else {
                  Toast.makeText(getApplicationContext(), "Select GROUP, N and ORDER", Toast.LENGTH_SHORT).show();
              }
          }
      }
  
      @Override
      public void onCheckedChanged(RadioGroup group, int checkedId) {
          // TODO Auto-generated method stub
          switch (checkedId) {
              case R.id.procOrderASC:
                  order = 0;
                  orderCheck = true;
                  break;
              case R.id.procOrderDSC:
                  order = 1;
                  orderCheck = true;
                  break;
          }
      }
  }
  </code></pre>
  
  <p>Thanks,</p>
  
  <p>favolas</p>