【发布时间】:2021-04-24 00:32:50
【问题描述】:
我的片段中有一个按钮,可以打开一个BottomSheetDialogFragment。如果用户在 BottomSheetDialogFragment 上选择了一个项目,我想通知主机片段。为了实现这一点,我在我的 BottomSheetDialogFragment 中做了一个接口。但是,该接口仅与宿主活动通信,而不与片段通信。如何将对话框中的信息发送到片段?
这是我的界面:
public interface BottomSheetListener {
void onButtonClicked(int index);
}
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
try {
mListener = (BottomSheetListener) context;
} catch (ClassCastException e) {
throw new ClassCastException(context.toString() + " must implement BottomSheetListener");
}
}
【问题讨论】:
标签: android android-fragments android-bottomsheetdialog bottomsheetdialogfragment