Anon
Anon

Reputation: 39

Android: how to set the number of items in a GridView

I only set the num columns in properties of a GridView. Nowhere to set the number of items

I google but only got some questions about how to fix the rows of GridView. I looking for in API GridView also, but there is no function to do that.

Someone teach me? Thanks

Upvotes: 2

Views: 1453

Answers (1)

Veeru
Veeru

Reputation: 4936

You cannot set the number of items directly on a grid view. This has to be done using its adapter and set the number of items in the adapter.

Usually a variable/array holding the items is created before an adapter is passed to the grid. This will populate the grid accordingly.

To be specific, this is the adapter function

@Override
    public int getCount() {
        return "HOW MANY ITEMS YOU WANT TO SHOW";
    }

Upvotes: 2

Related Questions