Android: onPrepareDialogBuilder, onClick & setItemChecked -
i've spent on week trying figure out way limited multi selection preference list. nothing i've tried works. i'm ready give on android if seemingly simple hard. i've been programming long time , don't remember being beaten badly this. have assume not understanding basic. hope can point me in right direction.
here simplest code can think off should work. not clear checkbox when setting false, i've tried true well. why doesn't work? if not work, will?
any 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 entries array , entryvalues array both same length"); } // added wjt since loading entries values after instantiation // need clicked indexes setup now, not have been // set in 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,
\ ^ / l l
here's how approach problem:
step #1: working in standalone throwaway test activity. forget preferences. forget dialogs. focus on functionality of having choice_mode_multiple
listview
where, after number of items checked, unchecked items become disabled.
step #2: functionality step #1 working in form of custom widget. this, mean implement subclass of listview
(i guess...might container if there's more listview
) bakes in of need step #1.
step #3: create custom dialogpreference
subclass uses custom widget step #2.
for example, here sample project have custom colormixer
widget, rolled colorpreference
.
Comments
Post a Comment