Search This Blog

23 April 2010

Checkbox dialog

Building on the previous example, this time we want to be able to select and unselect various items.  Because of that, this example will not actually close the dialog.

Open and add a variable for storing the initial states:
final boolean[] states = {false, false, true};

Replace the setItems or setSingleChoiceItems with:
        builder.setMultiChoiceItems(items, states, new DialogInterface.OnMultiChoiceClickListener(){
            public void onClick(DialogInterface dialogInterface, int item, boolean state) {
                Toast.makeText(getApplicationContext(), items[item] + " set to " + state, Toast.LENGTH_SHORT).show();

Redeploy (mvn clean install) and you should be able to (un)select different ones.

No comments:

Post a Comment