How to pass data to BottomSheetDialogFragment?

46
June 12, 2019, at 09:10 AM

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()?

Answer 1

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);
}
READ ALSO
In spring batch, how to insert a piece of code just after reading a list of item by bulk, with given list of item as parameter?

In spring batch, how to insert a piece of code just after reading a list of item by bulk, with given list of item as parameter?

I'm using spring batch in chunk mode for processing itemsI read them by bulk(6000 items by bulk), process them one by one, and write them all

32
Save and Restore workbench on E4

Save and Restore workbench on E4

in my RCP 3x-based Client-/Server-Application, I save the workbench state (e

31
What causes grails application to create more threads in some deployments

What causes grails application to create more threads in some deployments

Not 100% sure how to ask thisSkip to last paragraph for the actual question, the rest is background information

38
How to assign random unique value generated by the database to Hibernate POJO's field

How to assign random unique value generated by the database to Hibernate POJO's field

The problem is that I need to generate unique value for the one of my POJOs field in JavaI am using Hibernate

29