Record ListView Scroll Stop position and set display location in Android project

Source: Internet
Author: User

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


    1. //Declaration record stops scrolling when the visible position   

    2. Private   int stop_position;

[Java] View Plaincopy


  1. @Override   

  2. public void onscrollstatechanged (Abslistview view, int Scrollstate) {

  3. //TODO auto-generated method stub

  4. //Determine if it is the last line and stop scrolling

  5. if (islastrow && scrollstate = = onscrolllistener.scroll_state_idle) {

  6. //Get visible location

  7. Stop_position = Lv_categories.getfirstvisibleposition ();

  8. //Determine if it is the last page

  9. if (pageinfo.getnowpage () = Pageinfo.getcountpage ()) {

  10. //query next page of data

  11. categorymanager.queryobjects (pageinfo.getnowpage () + 1);

  12. }

  13. //Remember to change the logo to False

  14. Islastrow = false  ;

  15. }

  16. }

  17. @Override

  18. public void onscroll (Abslistview view, int Firstvisibleitem,

  19. int visibleitemcount, int totalitemcount) {

  20. if ((Firstvisibleitem + visibleitemcount) >= totalitemcount) {

  21. Islastrow = true  ;

  22. }

  23. }




2. Start the position again


[Java] View Plaincopy


    1. To set the adapter for a ListView control

    2. Lv_categories.setadapter (adapter);

    3. Set the visible position of the ListView start

    4. Lv_categories.setselection (stop_position);



Record ListView Scroll Stop position and set display location in Android project

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.