Android ListView Load More location issues

Source: Internet
Author: User

When we use Android to load more data in the ListView, the view will slide to the first if you re-adapter each time.


Later I found that the ListView has a way to get to the top of which one

int position = Mlistview.getfirstvisibleposition ();

This allows you to get the number of the first line currently displayed.

So I have found a way to load more data after that. If we set his position, we won't have to scroll to the first bar.

Mlistview.setselection (position);


But look closely, there is a little movement, because the method above is to get the first full display of the item, there may be a half item, if you position is not exactly the top of it, he will let it just right, there will be a deviation.

And then I found that there was another way

Mlistview.setselectionfromtop (position, top);


So this top is the first position item is already away from the top.

How did you get it? There is also a method:

View v = mlistview.getchildat (0);
top = (v = = null)? 0:v.gettop ();



Android ListView Load More location issues

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.