luizgrp / SectionedRecyclerViewAdapter

An Adapter that allows a RecyclerView to be split into Sections with headers and/or footers. Each Section can have its state controlled individually.
MIT License
1.68k stars 372 forks source link

BUG: Viewtype is wrong #146

Closed rossiriccardo21 closed 5 years ago

rossiriccardo21 commented 5 years ago

I was using your library and only the elements at the first and second position(both in 1 section) had the correct ViewType. For the next positions (New Section) the ViewType was greater than 6 so switch ended up always in the default case. By adding sectionAdapter.getItemViewType(position) % 6 in the switch, the ViewType can actually end up in the 6 different cases that each section can have(header,footer, loaded, empty,loading, failed).

luizgrp commented 5 years ago

Hi @rossiriccardo21, that switch is specific to that screen, which only has two types of views: header and item. I don't see any issue with that? Do you see any issues in that example in the demo app?

rossiriccardo21 commented 5 years ago

Hi @luizgrp , I didn't download the demo app, anyway I followed the example code to set up my sectionedRecyclerView with a GridLayout that displays headers with a width that covers the whole screen, while displays the items on two columns. The first section of the list was displayed correctly, the others though were not: every cell was displayed as an item (taking up only half of the screen) even if it had the layout of an header. Debugging I noticed that the switch did not end up in any of the case listed in your code, instead it entered a "7th case". Therefore I printed the integer value of the viewType and only in the first section was a number lesser than 6, for the following sections it was greater than 6, but not in a random way. Looking at your code I noticed that simply adding % 6 to the int value of the ViewType I was given, I got the correct ViewType that was <6 and >0. This way the viewtype of every cell is correct and the RecyclerView diplayed the headers as headers, taking up the whole screen, and the items as items, taking up half of the screen.

luizgrp commented 5 years ago

nice to hear that it's working well for you 👍

this piece of code that you want to change is not from the library itself, but for the demo app, and that screen only has 2 view types, hence we don't need that code. as you also said, you didn't run the demo app so you didn't test if this code works for the demo app, so I'm closing it.