Code example for AlertDialog.Builder

Methods: setMultiChoiceItems

        if (mEntries.length != mEntryKeys.length || mEntryKeys.length != mInitialValues.length) {
            throw new IllegalStateException(
                    "MultiChoicePreference entries, entryKeys, and initialValues arrays must be the same length"); 
        builder.setMultiChoiceItems(mEntries, mValues, new DialogInterface.OnMultiChoiceClickListener() {
            public void onClick(DialogInterface dialog, int which, boolean val) {
                // mValues is automatically updated when checkboxes are clicked 
                // enable positive button only if at least one item is checked 
                boolean enabled = false;
                for (int i = 0; i < mValues.length; i++) {
                    if (mValues[i]) {
                        enabled = true;
                Button button = ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE);
                if (button.isEnabled() != enabled)
Connect your IDE to all the code out there  Get Codota for Java