Overall idea: When sliding the Lictview, record the position of the ListView and position it when positioning.
1. Add Global variables
private int scrolledx = 0;
private int scrolledy = 0;
2, Oncreate () Add scrolling event listener
Classeslv.setonscrolllistener (New Onscrolllistener () {
/**
* Called when the scrolling state changes
*/
@Override
public void Onscroll (Abslistview view, int firstvisibleitem,
int visibleitemcount, int totalitemcount) {
}
@Override
public void onscrollstatechanged (Abslistview view, int scrollstate) {
if (scrollstate = = Onscrolllistener.scroll_state_idle) {
try {
Scrolledx = View.getfirstvisibleposition ();
LOG.I ("Scroll X", string.valueof (Scrolledx));
Scrolledy = View.getchildat (0). GetTop ();
LOG.I ("Scroll Y", string.valueof (Scrolledy));
} catch (Exception e) {
}
}
}
//
});
3, the activity restarts, restore the original positioning.
public void Onback () {
Classeslv.setselectionfromtop (Scrolledx, scrolledy);
}
protected void Onresume() {
Classeslv.scrollto (Scrolledx, scrolledy);
Onback ();
Initdatafromnet ();
Isclick = 0;
Super.onresume ();
}
The ListView is positioned to the last displayed location