Home » Android » java – Android: Difference between getCount() and getChildCount() in ListView

java – Android: Difference between getCount() and getChildCount() in ListView

Posted by: admin April 23, 2020 Leave a comment

Questions:

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

How to&Answers:

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…

Answer:

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.

Answer:

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