Preserving listview scroll position in android? -
i read how maintain position of listview
that solution works if activity/fragment not destroyed. if is, screen rotation, think need set scroll position bundle in onsaveinstancestate. otherwise, when resuming activity/fragment, index 0 because not stopped, destroyed after rotating screen.
so saved scroll position in fragment's bundle in onsaveinstancestate , set position in onactivitycreated:
@override public void onsaveinstancestate(bundle savedinstancestate) { savedinstancestate.putint("scrollpos", listv.getfirstvisibleposition()); super.onsaveinstancestate(savedinstancestate); } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { .... int startindex; if(savedinstancestate == null) startindex = 0; else startindex = savedinstancestate.getint("scrollpos"); questionslv.setselectionfromtop(startindex, 0); homecoming v; } i see index saved in onactivitycreated after rotate screen, listview still starts top; why?
android listview android-fragments
No comments:
Post a Comment