Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: onPrepareDialogBuilder, onClick & setItemChecked
    primarykey
    data
    text
    <p>I've spent over a week trying to figure out a way to do a Limited Multi Selection Preference list. Nothing I've tried works. I'm ready to give up on Android if something seemingly simple is so hard. I've been programming a long time and don't remember being beaten up this badly by something like this. I have to assume I am not understanding something basic. I hope someone can point me in the right direction. </p> <p>Here is the simplest code I can think off that should work. It does not clear the checkbox even when setting it to false, I've tried true as well. Why doesn't that work? If that will not work, what will?</p> <p>Any help would be most appreciated.</p> <pre><code> @Override protected void onPrepareDialogBuilder(Builder builder) { CharSequence[] entries = getEntries(); CharSequence[] entryValues = getEntryValues(); if (entries == null || entryValues == null || entries.length != entryValues.length ) { throw new IllegalStateException( "ListPreference requires an entries array and an entryValues array which are both the same length"); } // Added by WJT since we are loading the entries values after instantiation // we need the clicked indexes to be setup now, they would not have been // set up in the constructor if ((mClickedDialogEntryIndices == null) || (mClickedDialogEntryIndices.length == 0)) mClickedDialogEntryIndices = new boolean[getEntries().length]; restoreCheckedEntries(); builder.setMultiChoiceItems(entries, mClickedDialogEntryIndices, new DialogInterface.OnMultiChoiceClickListener() { public void onClick(DialogInterface dialog, int which, boolean val) { mDlg = (AlertDialog)getDialog(); mListView = (ListView)mDlg.getListView(); if (val) { if (mSelectedCount &lt; mLimit) { mClickedDialogEntryIndices[which] = val; mSelectedCount++; } else { mListView.setItemChecked(which, false); Toast.makeText(getContext(), R.string.newsLimitExceededMessage, Toast.LENGTH_LONG).show(); } // (mSelectedCount &lt; mLimit) } else { mClickedDialogEntryIndices[which] = val; mSelectedCount--; } // (val) } // void onClick(DialogInterface dialog, int which, boolean val) }); // DialogInterface.OnMultiChoiceClickListener() } // void onPrepareDialogBuilder(Builder builder) </code></pre> <p>Thanks,</p> <p>\ ^ / i l l </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload