The ListView is positioned to the last displayed location

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.