Hi,
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.
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?
Any help would be most appreciated.
@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 < mLimit)
{
mClickedDialogEntryIndices[which] = val;
mSelectedCount++;
}
else
{
mListView.setItemChecked(which, false);
Toast.makeText(getContext(),
R.string.newsLimitExceededMessage,
Toast.LENGTH_LONG).show();
} // (mSelectedCount < mLimit)
}
else
{
mClickedDialogEntryIndices[which] = val;
mSelectedCount--;
} // (val)
} // void onClick(DialogInterface dialog, int which, boolean val)
}); // DialogInterface.OnMultiChoiceClickListener()
} // void onPrepareDialogBuilder(Builder builder)
Thanks,
\ ^ / i l l