Let the ListView return to its original position

Source: Internet
Author: User

Let the ListView return to its original position

When you jump from one item in the ListView to another activity, the ListView may need to refresh (reload the data source), and the ListView will return to its original state, which is displayed starting with the first item. All we have to do is get it back to where it was.

//record the location of the current ListView    Private intcurrent_listview_item_position = 0; @Override Public voidOnPause () {Super. OnPause (); Current_listview_item_position= Lvofcontact.getfirstvisibleposition ();//gets the first of the current ListViewSystem.out.println ("OnPause remembers the current position:" +current_listview_item_position); } @Override Public voidOnresume () {Super. Onresume (); Lvofcontact.setselection (current_listview_item_position);//back to the original positionSystem.out.println ("Scroll to the original location:" +current_listview_item_position); }//reload the data source in the ListView//call the method, you can go back to the original position.lvofcontact.setselection (current_listview_item_position);

Let the ListView return to its original position

Related Article

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.