android - Custom ListView doesn't save it's state -
i using standart android listview
simle_list_item_multiple_choice
item layout , custom adapter. saved it's stated on pause , restored on resume. after few days of working on i've implemented sectionindexer
, stickylistheadersadapter
interface within adapter , changed listview
stickylistheaderslistview
this library. there other changes in application these attached listview
. when application resumes working listview coming scrolled begining , items unchecked. i've tryed remove sectionindexer
interface , sticky headers back upwards had no effect. maybe there hidden options of listview need enable?
(tried savestate
property - no effect)
public class wordadapter extends arrayadapter<word> implements sectionindexer, stickylistheadersadapter{ // ----------------------------------------------------------------------- // // fields // // ----------------------------------------------------------------------- private int mresid; private list<word> mlist; private string[] msectionnames; private stickylistheaderslistview mlistview; private int[] msectionindexes; private boolean mheadersenabled; // ----------------------------------------------------------------------- // // constructor // // ----------------------------------------------------------------------- public wordadapter(context context, stickylistheaderslistview listview, int resid, list<word> list, string[] sectionnames, int[] sectionindexes, boolean enableheaders) { super(context, resid, list); mresid = resid; mlist = list; mlistview = listview; msectionindexes = sectionindexes; msectionnames = sectionnames; mheadersenabled = enableheaders; } @override public view getview(int position, view convertview, viewgroup parent) { viewholder holder; if (convertview == null) { convertview = layoutinflater.from(getcontext()).inflate(mresid, parent, false); holder = new viewholder(); holder.root = convertview; holder.textview = (textview) convertview.findviewbyid(android.r.id.text1); holder.checkbox = (checkbox) convertview.findviewbyid(android.r.id.checkbox); convertview.settag(holder); } holder = (viewholder) convertview.gettag(); holder.textview.settext(getitem(position).getvalue()); if(mlistview.isitemchecked(position)) holder.root.setbackgroundcolor(getcontext().getresources().getcolor(r.color.highlight)); else holder.root.setbackgroundcolor(getcontext().getresources().getcolor(android.r.color.transparent)); homecoming convertview; } @override public view getheaderview(int position, view convertview, viewgroup parent) { if(!mheadersenabled) homecoming new view(getcontext()); headerviewholder holder; if (convertview == null) { holder = new headerviewholder(); convertview = layoutinflater.from(getcontext()).inflate(r.layout.list_item_header, parent, false); holder.labelview = (textview) convertview.findviewbyid(r.id.list_item_header_label); convertview.settag(holder); } else { holder = (headerviewholder) convertview.gettag(); } string label; if(msectionnames != null){ label = msectionnames[getsectionforposition(position)]; holder.labelview.settext(label); } homecoming convertview; } @override public long getheaderid(int position) { long result = getsectionforposition(position); homecoming result; } @override public int getpositionforsection(int section) { homecoming (msectionindexes == null || section < 0 ) ? 0 : (section == msectionindexes.length ? mlist.size():msectionindexes[section]); } @override public int getsectionforposition(int position) { if(msectionindexes != null && position >= msectionindexes[0]) { for(int = 0; < msectionindexes.length; ++i) if(position < msectionindexes[i]) homecoming i-1; homecoming (msectionindexes.length - 1); } homecoming 0; } @override public object[] getsections() { homecoming msectionnames == null ? new object[0] : msectionnames; } // ------------------------------------------------------------------------------- // // internal classes // // ------------------------------------------------------------------------------- private static class viewholder { public view root; public textview textview; public checkbox checkbox; } private static class headerviewholder { public textview labelview; }
here adapter code.
android listview savestate custom-adapter custom-lists
No comments:
Post a Comment