Nastro
Nastro

Reputation: 1769

How to pass data to BottomSheetDialogFragment?

I have a BottomSheetDialogFragment class. Looks like this:

public class BottomSheetAddProp extends BottomSheetDialogFragment

It has a method:

@Override
public View onCreateView

In this method I create a RecyclerView with RecycleAdapter for photos.

        recyclerPhotos = v.findViewById(R.id.recyclerPhotos);
        recyclerPhotos.setHasFixedSize(true);
        layoutManagerPhotos = new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false);
        recyclerAdapterPhotos = new AdapterPhotos(selectedPhotos, getActivity());
        recyclerPhotos.setLayoutManager(layoutManagerPhotos);
        recyclerPhotos.setAdapter(recyclerAdapterPhotos);

The data about chosen photos comes to onActivityResult method and I have to performe a recyclerAdapterPhotos.notifyDataSetChanged() to update the RecyclerView List. But in Activity I don't have this recyclerAdapterPhotos because it was created inside BottomSheetAddProp.

My question is - how to make .notifyDataSetChanged() inside onActivityResult()?

Upvotes: 0

Views: 214

Answers (1)

Alexei Artsimovich
Alexei Artsimovich

Reputation: 1184

Add a method in your dialog fragment:

public void updatedData(Data data) {
    adapter.setData(data);
}

Hold the reference to your fragment inside activity. Then in onActivityResult method just pass the data through the method above:

void onActivityResult(int requestCode, int resultCode, Intent data) {
    Data data = ...
    dialogFragment.updateDate(data);
}

Upvotes: 1

Related Questions