The ListView control is frequently used in projects, and when you want to record records when scrolling is stopped, what happens when you click Load new data and start displaying from the location of the record? is divided into the following steps
1. Record Location Codes
[Java] View Plaincopy
//Declaration record stops scrolling when the visible position
Private int stop_position;
[Java] View Plaincopy
@Override
public void onscrollstatechanged (Abslistview view, int Scrollstate) {
//TODO auto-generated method stub
//Determine if it is the last line and stop scrolling
if (islastrow && scrollstate = = onscrolllistener.scroll_state_idle) {
//Get visible location
Stop_position = Lv_categories.getfirstvisibleposition ();
//Determine if it is the last page
if (pageinfo.getnowpage () = Pageinfo.getcountpage ()) {
//query next page of data
categorymanager.queryobjects (pageinfo.getnowpage () + 1);
}
//Remember to change the logo to False
Islastrow = false ;
}
}
@Override
public void onscroll (Abslistview view, int Firstvisibleitem,
int visibleitemcount, int totalitemcount) {
if ((Firstvisibleitem + visibleitemcount) >= totalitemcount) {
Islastrow = true ;
}
}
2. Start the position again
[Java] View Plaincopy
To set the adapter for a ListView control
Lv_categories.setadapter (adapter);
Set the visible position of the ListView start
Lv_categories.setselection (stop_position);
Record ListView Scroll Stop position and set display location in Android project