我从 fragment A 开始 bottomSheetDialogFragment。 我想从 bottomSheetDialogFragment 中选择日期,然后将其设置在 fragment A 中。
选择日期已经完成了,我只想在 fragment A中获取它以在某些字段中进行设置。
如何获取值? 有什么建议吗?
最佳答案
像这样创建一个接口(interface)类
public interface CustomInterface {
public void callbackMethod(String date);
}
在您的Activity
或Fragment
中实现此接口(interface)。并创建此接口(interface)的对象。
private CustomInterface callback;
在onCreate
或onCreateView
中初始化
callback=this;
现在,当您调用它时,将此回调传递到您的 BottomSheetDialogFragment
构造函数中。
yourBottomSheetObject = new YourBottomSheet(callback);
yourBottomSheetObject.show(getSupportFragmentManager()," string");
现在在 BottomSheetFragment 的构造函数中
私有(private)自定义接口(interface)回调;
public SelectStartTimeSheet(CustomInterface callback){
this.callback=callback;
}
最后使用这个回调对象来设置你的日期
callback.callbackMethod("your date");
您将在您的 fragment 或您在 callbackMethod
函数中的 Activity 中收到此日期。
关于android - 从 Bottom Sheet 对话框 fragment 中获取值(value),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49794739/