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 ()));
}
});