I'm using BottomSheetDialogFragment from the support library and it warns me that the function setupDialog() should only be used within the library group. But this function is the place where I initialize my dialog:
@Override
public void setupDialog(final Dialog dialog, int style) {
super.setupDialog(dialog, style);
FragmentArgs.inject(this);
dialog.setOnShowListener(dialogINterface -> {
if(dialog.getWindow() != null) {
dialog.getWindow().setLayout(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.MATCH_PARENT);
}
});
BottomSheetStatisticsExportBinding binding = DataBindingUtil.inflate(
LayoutInflater.from(getContext()),
R.layout.bottom_sheet_statistics_export,
null,
false
);
View contentView = binding.getRoot();
dialog.setContentView(contentView);
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) ((View) contentView.getParent()).getLayoutParams();
CoordinatorLayout.Behavior behavior = params.getBehavior();
if( behavior != null && behavior instanceof BottomSheetBehavior )
((BottomSheetBehavior) behavior).setBottomSheetCallback(bottomSheetBehaviorCallback);
for (Export export : exports)
binding.flexbox.addView(new ExportItemView(getContext(), export));
}
The warning is because I'm using the super method. But what should I do instead? Should I move my code inside another function (onCreateDialog(), onResume()...?), should I remove the call to the super?
Anyone knows?
Should I move my code inside another function (onCreateDialog(), onResume()...?)
Yes. As it demonstrates in the DialogFragment documentation (which BottomSheetDialogFragment extends), you should use onCreateView() to set up your dialog.
The View you return from this method will be set as the content view for the dialog provided by onCreateDialog(). And the getDialog() method can be used from within onCreateView() to make any adjustments to the aforementioned Dialog.
onCreateDialog() would be used to replace the default Dialog. Which in your case you probably don't want to do; considering that is the method BottomSheetDialogFragment uses to replace the default Dialog with a BottomSheetDialog (in fact, it is the only method BottomSheetDialogFragment overrides).
Here are the BottomSheetDialog and BottomSheetDialogFragment classes I created to replace the support library versions (see comments for more information).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With