7

The documentation says the following about getItemCount():

Returns the number of items in the adapter bound to the parent RecyclerView. Note that this number is not necessarily equal to State#getItemCount().

So, does it return all the items in the adapter or the items that are visible on the screen? I don't get it. Can someone explain this method?

Aravind Pulagam
  • 145
  • 2
  • 10

4 Answers4

2

getItemCount() - returns The number of items currently available in adapter

  • This method returns the size of the collection that contains the items we want to display.

    @Override
    public int getItemCount() {
        return models.size();
    }
    
  • It returns The number of items currently available in adapter.

Reference:

Zoe
  • 27,060
  • 21
  • 118
  • 148
Vidhi Dave
  • 5,614
  • 2
  • 33
  • 55
1

It returns the size of all the items in the adapter not only the size of visible items. In simple term, getItemCount() returns the size for the whole adapter.

dazed'n'confused
  • 231
  • 3
  • 13
1

The getItemCount() method returns the number of list items.The number of items this adapter is adapting.

Reference Code :

ArrayList<Games> list;

    public int getItemCount() {
         return list.size();
    }

The getItemCount() method is return the number of items in the collection you're adapting, in above case list, which is just an array of Game objects. Arrays have a property that allows you to get their length which is all you need to return.

Abhishek kumar
  • 4,347
  • 8
  • 29
  • 44
0

getitemCount() return how many items you want to show in the recyclerView

Elikill58
  • 4,050
  • 24
  • 23
  • 45