-1

I am currently working on a refactoring task which requires replacing ListView(GridView) by RecyclerView.

In a part of the job, it requires to get the span count. As the former code has a method to get the number of columns of GridView like this:

public int getNumColumns()

Then I am wondering that if there is a same method in RecyclerView?

Your answers are highly appreciated.

Sincerely, Jack

I tried something like:

mRecyclerView.getLayoutManager().getColumnCountForAccessibility()

But apparently, this is only for the sake of horizontal scrolling.

public int getNumColumns()
Adam
  • 2,726
  • 1
  • 9
  • 22
Jack
  • 13
  • 4

1 Answers1

0

Try using,

GridLayoutManager layoutManager = (GridLayoutManager)mRecyclerView.getLayoutManager();
int spanCount = layoutManager.getSpanCount()
Saikrishna Rajaraman
  • 3,205
  • 2
  • 16
  • 29