android - How can I save the ListView's scroll position -
how can save listview's scroll position when choose 1 item in listview, , want return in same listview .
suppose have 2 fragments – listfragment , someotherfragment. replace listfragment someotherfragment.
fragmentmanager manager = getfragmentmanager(); fragmenttransaction transaction = manager.begintransaction(); transaction.replace(r.id.content_frame, fragment); transaction.addtobackstack(null); transaction.commit();
the best solution know
// save listview state (= includes scroll position) parcelable
parcelable state = listview.onsaveinstancestate(); // restore previous state (including selected item index , scroll position)
listview.onrestoreinstancestate(state); you can restore last saved position after setting adapter -
// save listview state (= includes scroll position) parceble parcelable state = listview.onsaveinstancestate(); // e.g. set new items listview.setadapter(adapter); // restore previous state (including selected item index , scroll position) listview.onrestoreinstancestate(state); you can refer here more details.
Comments
Post a Comment