ListView. getCount () and ListView. getChildCount () OnScrollListener ()

Source: Internet
Author: User

ListView. getCount () (actually AdapterView. getCount () returns the value returned by its Adapter. getCount. That is, "Total number of items contained ".

ListView. getChildCount () (ViewGroup. getChildCount) returns the number of child views contained in the display layer ".

What is the difference between the two? If the items in the ListView are relatively small and you do not need to scroll to display them all, the two are equivalent. If the number of items is large and you need to scroll to view all, getChildCount () <getCount () getChildCount () returns the number of items currently visible.

Java code

ListView. setOnScrollListener (new OnScrollListener (){

@ Override

Public void onScrollStateChanged (AbsListView view, int scrollState ){

// TODO Auto-generated method stub

}

@ Override

Public void onScroll (AbsListView view, int firstVisibleItem,

Int visibleItemCount, int totalItemCount ){

// TODO Auto-generated method stub

/** FirstVisibleItem indicates the first ListItem on the current screen (some of the displayed listitems are also counted)

Position of the entire ListView (subscript starts from 0 )**/

Log. I ("firstVisibleItem", String. valueOf (firstVisibleItem ));

/** VisibleItemCount indicates the total number of listitems that can be seen on the current screen (some listitems are also calculated **/

Log. I ("visibleItemCount", String. valueOf (visibleItemCount ));

/** TotalItemCount indicates the total number of listitems in ListView **/

Log. I ("totalItemCount", String. valueOf (totalItemCount ));

/** ListView. getFirstVisiblePosition () indicates the first ListItem on the current screen (the first ListItem is also displayed)

* The Position of the entire ListView (the subscript starts from 0 )**/

Log. I ("firstPosition", String. valueOf (listView. getFirstVisiblePosition ()));

/** ListView. getLastVisiblePosition () indicates the last ListItem on the current screen (the last ListItem must be fully displayed)

* The Position of the entire ListView (the subscript starts from 0 )**/

Log. I ("lasPosition", String. valueOf (listView. getLastVisiblePosition ()));

}

});

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.