Android: Difference between getCount() and getChildCount() in ListView
Asked Answered
B

3

32

What is difference between getCount() and getChildCount() in ListView?

Bedim answered 20/4, 2012 at 8:33 Comment(0)
M
71

getCount() returns you a count of items in Adapter (total in list), getChildCount() is a ViewGroup method that returns you number of subviews. ListView actively reuses views so if your list has 1000 items getCount() will return 1000, getChildCount() - around 10 or so...

Municipalize answered 20/4, 2012 at 8:36 Comment(1)
up vote for this answer, for I've been stupid enough to do listview.getChildAt(getCount() -1) and get null pointer exception.Ostensive
P
3

getCount() is the number of items in the adapter while getChildCount() refers to the ViewGroup's method that returns the number of the views that this view contains.

Plowman answered 20/4, 2012 at 8:37 Comment(0)
G
0

In your adapter there is one Method getChildrenCount();that decide how many child you want to create.

  @Override
    public int getChildrenCount(int groupPosition) {
        return 1;
    }
Guttersnipe answered 22/12, 2015 at 8:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.