java – Android Studio – How to create a recyclerview with unique buttons-ThrowExceptions

Exception or error:

I am creating an app that needs a recyclerview but instead of the usual textviews, imageviews etc, I need the recyclerview to contain buttons. I need to be able to rearrange the order of the recyclerview. Is there any way I could do this?

How to solve:

Welcome to Stackoverflow,

You can do it by passing datasource to recyclerview like List<String> buttonIds.
Inside onCreateViewHolder(), create a xml layout which contains Button and bind buttonId in onBindViewHolder.

To rearrange position by code, you can switch position of buttonIds by using Collections.swap() then calls adapter.notifyDataSetChanged().

If you want user changes position by dragging. You can check out

Leave a Reply

Your email address will not be published. Required fields are marked *