Monday, February 5, 2018

Bus Seating Arrangement same as in RedBus, Android

Leave a Comment

I am trying to implement a bus seat booking application which is very similar to RedBus app. I came across over the seating arrangement in that and i was struck over there.

I really need your help in achieving this. I have tried with Recycler View but that doesn't get me into the exact layout.

I have tried with recycler view and my layout goes as,

enter image description here

But, the actual screen shot from redbud application is as,

enter image description here

I have gone through one of the code that is available in git

https://github.com/TakeoffAndroid/SeatBookingRecyclerView

But, using the above code, i can get the layout design but the problem with this is, Say like if there are 41 seats, but using the above git code it will be showing 33 seats on the screen comes up like as,

enter image description here

Help would be really appreciated.

Snippet Code:

     numOfColumns = 4;      mArrayBusSeats = new ArrayList<>();     for (int i = 0; i < mArraySeats.size(); i++) {                 if (i % numOfColumns == 0 || i % numOfColumns == (numOfColumns - 1)) {                     BusLayoutModel model = mArraySeats.get(i);                     model.setSeatType(AbstractItem.TYPE_EDGE);                     mArrayBusSeats.add(model);                 } else if (i % numOfColumns == 1 || i % numOfColumns == (numOfColumns - 2)) {                     BusLayoutModel model = mArraySeats.get(i);                     model.setSeatType(AbstractItem.TYPE_CENTER);                     mArrayBusSeats.add(model);                 } else {                     BusLayoutModel model = new BusLayoutModel();                     model.setSeatType(AbstractItem.TYPE_EMPTY);                     mArrayBusSeats.add(model);                 }             } 

2 Answers

Answers 1

Have you tried with the number of coulum 5 ??

I haven't use the library but when I checked it I think I should be done like this

numOfColumns = 5;      mArrayBusSeats = new ArrayList<>();     for (int i = 0; i < mArraySeats.size(); i++) {              BusLayoutModel model = mArraySeats.get(i);                  if (i % numOfColumns == 0 || i % numOfColumns == 4) {                     model.setSeatType(AbstractItem.TYPE_EDGE);                     mArrayBusSeats.add(model);                 } else if (i % numOfColumns == 1 || i % numOfColumns == 3) {                     model.setSeatType(AbstractItem.TYPE_CENTER);                     mArrayBusSeats.add(model);                 } else {                     model.setSeatType(AbstractItem.TYPE_EMPTY);                     mArrayBusSeats.add(model);                 }             } 

Answers 2

In your Recycler View implementation try to reduce row height, as compared to redbus your row height is almost double.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment