-3

My RecyclerView in one activity is made up of an ArrayList of my custom object. Because this activity is in the edit mode, I would like to pass all the contents of this RecyclerView into another activity that is in non-edit mode. What is the best way to achieve this?

Thanks!

Zoe
  • 27,060
  • 21
  • 118
  • 148
Rachel Boey
  • 35
  • 1
  • 6

2 Answers2

1

You wouldn't pass an entire RecyclerView object to another Activity. How about just passing your ArrayList<CustomObject>? You can do that with GSON:

How to pass gson serialised object to Intent in android?

Of course you can reuse the same RecyclerView Adapter class. You just need to instantiate it separately in both Activities.

Gavin Wright
  • 3,124
  • 3
  • 14
  • 35
0

You don't need two activities. You can achieve your goal with a single activity. You can use some flag like isEditMode inside your adapter. It will be used to adapt interface for specific mode. When you need to change mode -- just change isEditMode field and then call adapter.notifyDataSetChanged().

Note. You also need change method onBindViewHolder of your adapter to react to a mode changing. Like:

@Override
public void onBindViewHolder(@NonNull K holder, int position) {
    if (isEditMode) {
        // Set up item for edit mode
    } else {
        // Set up item for non-edit mode
    }
Andrew Churilo
  • 2,229
  • 1
  • 17
  • 26