Differences between Listview.getcount () and Listview.getchildcount () and Onscrolllistener () parameters in Android

Source: Internet
Author: User

Istview.getcount () (actually Adapterview.getcount ()) returns the value returned by its adapter.getcount (). That is, the total number of items contained in the Item.

Listview.getchildcount () (Viewgroup.getchildcount) returns the "number of child View contained" on the display plane.

What's the difference between the two? When the item in the ListView is less than scrolling to show it all, the two are equivalent; Getchildcount () < GetCount () where the item number needs scrolling to view all of them Getchildcoun T () returns the Item count that is 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 in the current screen the first ListItem (partially displayed ListItem also counted)

Position throughout the ListView (subscript starting from 0) **/

LOG.I ("Firstvisibleitem", String.valueof (Firstvisibleitem));

/**visibleitemcount indicates the total number of ListItem (ListItem in part) that can be seen on the current screen **/

LOG.I ("VisibleItemCount", String.valueof (VisibleItemCount));

/**totalitemcount represents the total number of ListItem in the ListView **/

LOG.I ("Totalitemcount", String.valueof (Totalitemcount));

/**listview.getfirstvisibleposition () indicates that the first listitem of the screen (the first ListItem part of the display is counted)

* position in the entire ListView (subscript starting from 0) **/

LOG.I ("Firstposition", String.valueof (Listview.getfirstvisibleposition ()));

/**listview.getlastvisibleposition () in the current screen at the last ListItem (the last ListItem to be fully displayed in order to calculate)

* position in the entire ListView (subscript starting from 0) **/

LOG.I ("Lasposition", String.valueof (Listview.getlastvisibleposition ()));

}

});

Differences between Listview.getcount () and Listview.getchildcount () and Onscrolllistener () parameters in Android

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.