I'm using RecyclerView
with GridLayout
manager to make seat booking layout like travels.
My problem is how to auto detect spancount when my column is random?
I know spanCount = recyclerViewWidth / singleItemWidth;
, but the problem is singleItemWidth
is different, as the seat width is different.
This is the desired layout that I want:
... but I'm currently getting something like this:
This is the code I'm using to arrange the seat layout:
gridLayoutManager=new GridLayoutManager(this,totalRows, LinearLayoutManager.VERTICAL,
false);
gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
int rows=Integer.parseInt(upperlist.get(position).get("row"));
return (rows);///(int) (mRecyclerView.getMeasuredWidth()/ 10);
}
});
mRecyclerView.setLayoutManager( gridLayoutManager);
MyAdapter myAdapter=new MyAdapter(this,gridArray);
... where upperlist
hold these values:
[{cols=8, seatNumber=29U, row=4, zindex=1},
{cols=6,seatNumber=23U, row=4, zindex=1},
{cols=4,seatNumber=21U,row=4, zindex=1},
{cols=2, seatNumber=11U, row=4, zindex=1},
{cols=0,seatNumber=9U,row=4, zindex=1},
{cols=8,seatNumber=25U, row=2, zindex=1},
{cols=6,seatNumber=17U, row=2, zindex=1},
{cols=4,seatNumber=13U, row=2, zindex=1},
{cols=2,seatNumber=5U, row=2, zindex=1},
{cols=10, seatNumber=D2U,row=2, zindex=1},
{cols=0, seatNumber=1U, row=2, zindex=1},
{cols=8, seatNumber=26U, row=1, zindex=1},
{cols=6,seatNumber=18U, row=1, zindex=1},
{cols=4,seatNumber=14U, row=1, zindex=1},
{cols=2,seatNumber=6U, row=1, zindex=1},
{cols=0,seatNumber=2U, row=1, zindex=1}]
This is a single list, where I'm having different values for rows and columns. I therefore need a generalized method which can work on all layouts.