Java Code Examples for android.app.AlertDialog.Builder#setMultiChoiceItems()

The following examples show how to use android.app.AlertDialog.Builder#setMultiChoiceItems() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MultiSelectListPreference.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
protected void onPrepareDialogBuilder(Builder builder) {
    super.onPrepareDialogBuilder(builder);
    
    if (mEntries == null || mEntryValues == null) {
        throw new IllegalStateException(
                "MultiSelectListPreference requires an entries array and " +
                "an entryValues array.");
    }
    
    boolean[] checkedItems = getSelectedItems();
    builder.setMultiChoiceItems(mEntries, checkedItems,
            new DialogInterface.OnMultiChoiceClickListener() {
                public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                    if (isChecked) {
                        mPreferenceChanged |= mNewValues.add(mEntryValues[which].toString());
                    } else {
                        mPreferenceChanged |= mNewValues.remove(mEntryValues[which].toString());
                    }
                }
            });
    mNewValues.clear();
    mNewValues.addAll(mValues);
}
 
Example 2
Source File: MultiCheckPreference.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
protected void onPrepareDialogBuilder(Builder builder) {
    super.onPrepareDialogBuilder(builder);
    
    if (mEntries == null || mEntryValues == null) {
        throw new IllegalStateException(
                "ListPreference requires an entries array and an entryValues array.");
    }

    mOrigValues = Arrays.copyOf(mSetValues, mSetValues.length);
    builder.setMultiChoiceItems(mEntries, mSetValues,
            new DialogInterface.OnMultiChoiceClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                    mSetValues[which] = isChecked;
                }
    });
}
 
Example 3
Source File: MultiSelectListPreference.java    From YalpStore with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void onPrepareDialogBuilder(Builder builder) {
    super.onPrepareDialogBuilder(builder);

    if (mEntries == null || mEntryValues == null) {
        throw new IllegalStateException(
            "MultiSelectListPreference requires an entries array and "
                + "an entryValues array.");
    }

    if (mNewValues == null) {
        mNewValues = new HashSet<>();
        mNewValues.addAll(mValues);
        mPreferenceChanged = false;
    }

    final boolean[] checkedItems = getSelectedItems(mNewValues);
    builder.setMultiChoiceItems(mEntries, checkedItems,
        new DialogInterface.OnMultiChoiceClickListener() {
            public void onClick(DialogInterface dialog, int which,
                                boolean isChecked) {
                if (isChecked) {
                    mPreferenceChanged |= mNewValues
                        .add(mEntryValues[which].toString());
                } else {
                    mPreferenceChanged |= mNewValues
                        .remove(mEntryValues[which].toString());
                }
            }
        });
}
 
Example 4
Source File: MultipleChoicePreference.java    From matlog with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onPrepareDialogBuilder(Builder builder) {

    // convert comma-separated list to boolean array

    String value = getValue();
    Set<String> commaSeparated = new HashSet<>(Arrays.asList(StringUtil.split(value, DELIMITER)));

    CharSequence[] entryValues = getEntryValues();
    final boolean[] checked = new boolean[entryValues.length];
    for (int i = 0; i < entryValues.length; i++) {
        checked[i] = commaSeparated.contains(entryValues[i]);
    }

    builder.setMultiChoiceItems(getEntries(), checked, (dialog, which, isChecked) -> checked[which] = isChecked);
    builder.setPositiveButton(android.R.string.ok, (dialog, which) -> {

        checkedDialogEntryIndexes = checked;

        /*
         * Clicking on an item simulates the positive button
         * click, and dismisses the dialog.
         */
        MultipleChoicePreference.this.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
        dialog.dismiss();

    });
}
 
Example 5
Source File: MultiSelectListPreference.java    From haxsync with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void onPrepareDialogBuilder(Builder builder) {
	builder.setMultiChoiceItems(getEntries(), checkedEntryIndexes,
			new OnMultiChoiceClickListener() {

				@Override
				public void onClick(DialogInterface dialog, int which,
						boolean isChecked) {
					checkedEntryIndexes[which] = isChecked;
				}
			});
}
 
Example 6
Source File: CVListPreference.java    From callmeter with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onPrepareDialogBuilder(final Builder builder) {
    if (m) {
        builder.setMultiChoiceItems(getEntries(), checked,
                new DialogInterface.OnMultiChoiceClickListener() {
                    public void onClick(final DialogInterface dialog, final int which,
                            final boolean val) {
                        CVListPreference.this.checked[which] = val;
                    }
                });
    } else {
        super.onPrepareDialogBuilder(builder);
    }
}