0

I have a RecyclerView with a cell row that have a favorite button. I was searching on SO and found a question with the same thing that I want to do here : implementing "add to favourite" mechanism in RecyclerView

the problem is that is not clear for me for now.

I dont want to have 2 recyclerViews and delegate the view to the other one because I will need to have 2 onCreateViewHolders and will be really unconfortable to work with, also bad coded.

What I need to do is like a row and then move it to the top with the title Favorite on it.

What comes to my mind is just delete the item im clicking and moving it to the 0 position of my ArrayList<Object> , but if I move that element to the 0 position it will overwrite my current element in the 0 position. Instead, I need to create a transparent row cell that says for example Favorites, and then below that cell (assuming is before 0 position in my array) start adding the favorites below it.

I will illustrate what I need to do.

enter image description here

This image is in the same RecyclerView without creating a new one above to show favorites. What I need to do is clicking one element, removing it and just replace it at the top of the RecyclerView but with a text on the top that says favorites, and after that each element that I add to the favorite list is just placed below the latest one there, so I was wondering what is the best way to accomplish this behaviour

This is what I need, pressing to like below, and then have my liked rows above, all in one place.

enter image description here

Thanks for any hint !

Todd
  • 179
  • 15
  • it looks like two recyclerviews to me (the image you shared), one on top of each other that will be visible if any item is in the list, to keep things simple I feel that you should implement two recyclerviews, having said that what you're trying to do is also possible – MRah Sep 10 '18 at 14:33
  • I was talking that option with my supervisor and its not near any optimized way to do it, imagine inflating twice the same rows, binding all again, its not well coded to do so, but if I can just use 1 recycler and move the rows from bottom to top and stack them below another row that is favorites, that will be nice – Todd Sep 10 '18 at 14:35
  • I was thinking that when I press a row to add to favorites, add that element to another ArrayList lets call it favorites, and then just add that whole arraylist before the element with position 0 of my ArrayList of things, but I need to know how to arrange items before the 0 position – Todd Sep 10 '18 at 14:36
  • You don't need to use a different arraylist, you just need one more state variable (can be boolean) to indicate whether the item is added to favorite or not, in that case you don't need to add items before 0 element rather switch the position of the elements – MRah Sep 10 '18 at 14:54
  • yes, I think the best way is having 2 ArrayLists, one of the objects I show in the RecyclerView, and then other to store the favorites that im pressing, and then use Collection.Sort to just sort the two arraylists withh the same order criteria, and then place the favorites arraylist above the all objects arraylist, maybe that could work – Todd Sep 10 '18 at 15:01

0 Answers0