0

In getView(int position, View convertView, ViewGroup parent) method of an adapter how to know if position is reflecting the last column of the row ?

For example:

1 2 3
4 5 6
7 8 9

Let say this is GridView then element 3,6 and 9 are last column of row 1,2 and 3 respectively.

2 Answers2

0

Ask the grid, how many columns you have:

int numColumns = ((GridView) viewGroup).getNumColumns();

after that you could use the '%' operation:

boolean isLast = (position % numColums) == 0;
user3621165
  • 212
  • 4
  • 16
0

Solution: Call mGridView.getNumColumns() in getView() of the adapter.This will give the number of columns a row can have. Once we have that we can easily know which position is going to be the last column of the row.