I added an extra item to my recycler view as described in this post How to add a button at the end of RecyclerView? and now the view starts at the bottom, and every time I call "scrollToPosition" it doesn't work. The problem disappears when I change the number of items to the original instead of +1 Anyone has any idea how to solve this?
Asked
Active
Viewed 32 times
0
-
`+1` is actually a bad idea because it can lead to side effects like IndexOutOfBoundsException if you do not consider this `+1` in all of the situations where you access items of the data list. [Here is a detailed example](https://stackoverflow.com/questions/62363081/implementation-of-several-views-in-one-recyclerviews/62363549#62363549) of how you can implement multiple view holders in your adapter. You will be able to position your button anywhere you want in the list and in case you want this button to be removed you won't need to modify your adapter or handle special cases for it. – Jenea Vranceanu Aug 23 '20 at 09:48
-
ok, thanks. Without overriding the getItemCount how can I tell the RecyclerView to add an extra holder? – laserzt Aug 24 '20 at 09:18
-
"extra holder" should be just another entry in the data set. You can differentiate between items using `getItemViewType`. Check out the code by the link, especially `getItemViewType`. – Jenea Vranceanu Aug 24 '20 at 09:35
-
OK. My problem is that the data set is a PagedList. And it is not immutable, and I can't add items to it. – laserzt Aug 24 '20 at 10:29