0

I have RecyclerView which contains Users and I need button "Add user" at the bottom of RecyclerView (should looks like last item of RecyclerView and must be scrollable).

What is the best way to achieve this? Add new itemViewType to my Adapter? Or maybe there is more simple way with CoordinatorLayout (to scroll view below RecyclerView after one was scrolled all items down, if it is possible)? Second way is really convenient to show scrollable headers with RecyclerView.

LIFED
  • 467
  • 1
  • 4
  • 16
  • why not using std [floating action button](https://material.io/design/components/buttons-floating-action-button.html)? more [here](https://developer.android.com/guide/topics/ui/floating-action-button) – pskink Jan 22 '19 at 08:55
  • @pskink Design things. And also I'm interesing is it possible to add ViewGroup below scrolled recyclerView not using NestedScrollView, of course – LIFED Jan 22 '19 at 09:00
  • so, yes, use a different "item view type" - or you could do similar effect using `RecyclerView.ItemDecoration` – pskink Jan 22 '19 at 09:05
  • ItemDecoration sounds strange:D – LIFED Jan 22 '19 at 09:11
  • yes, sounds strange, but it doesnt require multiple item view types – pskink Jan 22 '19 at 09:12
  • @pskink can you show a simple example or post link to explanation please? – LIFED Jan 22 '19 at 09:15
  • https://medium.com/@paulnunezm/working-with-recyclerview-and-multiple-view-types-bb1e7dfc6993 – pskink Jan 22 '19 at 09:17
  • @pskink I mean how to use ItemDecoration as "ViewType" but thanks :D – LIFED Jan 22 '19 at 09:24
  • google("footer ItemDecoration") – pskink Jan 22 '19 at 09:26

1 Answers1

0

In this case you should add another ViewType with its ViewHolder. Here is a link to an answer where everything is explained https://stackoverflow.com/a/26245463/6329985

DawidJ
  • 1,245
  • 12
  • 19
  • What if I would have more complex "footer" of RecyclerView or even few "footers"? Should I put all of it to RecyclerView as different viewTypes? There is no way to use CoordinatorLayout? – LIFED Jan 22 '19 at 09:06
  • You should put them inside `RecyclerView` and add different viewTypes for every single item you want to use. If you would like to use `RecyclerView` inside another layout wraped in `NestedScrollView`, there would be a problem with view recycling (https://stackoverflow.com/questions/37590651/recyclerview-does-not-recycling-views-when-use-it-inside-nestedscrollview). Don't try to complicate your problem. – DawidJ Jan 22 '19 at 09:11
  • No, I just get rid of NestedScrollView:D But adding these viewTypes is so weard especially if they have nothing in common. And if I want to use this UserAdapter in other Activity/Fragment where I don't need to have this viewTypes. It's simple in this case with one button, but if there is more views.. – LIFED Jan 22 '19 at 09:21
  • It's not weird. You can always create another adapter or create adapter which will build itself depending on items passed via list, something like universal adapter. If you won't use `NestedScrollView` then you can't set `RecyclerView` height to match parent casue it will fill whole screen size and buttons below `RecyclerView` will be hidden. There is a point why `RecyclerView` can support different view types :) – DawidJ Jan 22 '19 at 09:28
  • Okay, and what can you say about adding "headers" at the AppBarLayout inside CoordinatorLayout with scroll flags? It will scroll up when recyclerView scrolls. RecyclerView is still "recycler" and everything looks good. Or it's bad practice and I should also put "header" to another viewType in Adapter? For example, "header" is Group (image, name) which has Users in RecyclerView. I should pass to Adapter Group and Users list? – LIFED Jan 22 '19 at 09:38
  • Putting "headers" like that is a bad idea becasue it will complicate your layout which is not needed here. Remeber that you should write your code to be eaisly extendable. Don't complicate your life. Your problem here is pretty simple and can you solve it just like I told in previous posts. As for other questions, you should create another post(s) for them. – DawidJ Jan 22 '19 at 09:57
  • Thank you for explanations :) I just never seen an examples with code of what I meaning: "Header Layout, some stuff.." -> RecyclerView with one or similar view types -> "Footer Layout, etc.." and all of it is in one RecyclerView. Well, I will try harder:D Or share link about it if you have one, please. – LIFED Jan 22 '19 at 10:08
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/187113/discussion-between-dawidj-and-lifed). – DawidJ Jan 22 '19 at 10:13