从“底部工作表"对话框片段中获取价值 [英] Get value from Bottom Sheet Dialog Fragment
问题描述
我正在从片段A开始bottomSheetDialogFragment.我想从该bottomSheetDialogFragment中选择日期,然后将其设置在片段A中.
I'm starting bottomSheetDialogFragment from a fragment A. I want to select the date from that bottomSheetDialogFragment then set it in the fragment A.
选择日期已经完成,我只想将其放在片段A中以在某些字段中进行设置.
The select date is already done, I just want to get it in the fragment A to set it in some fields.
我如何获得价值?有什么建议怎么做吗?
How can I get the value? Any suggestions how to do it?
推荐答案
创建这样的接口类
public interface CustomInterface {
public void callbackMethod(String date);
}
在您的 Activity
或 Fragment
中实现此界面.并创建此接口的对象.
Implement this interface in your Activity
or Fragment
. and make an object of this Interface.
private CustomInterface callback;
在 onCreate
或 onCreateView
callback=this;
现在在调用它时,在您的 BottomSheetDialogFragment
构造函数中传递此回调.
Now pass this callback in your BottomSheetDialogFragment
constructor when you call it.
yourBottomSheetObject = new YourBottomSheet(callback);
yourBottomSheetObject.show(getSupportFragmentManager()," string");
现在在您的BottomSheetFragment的构造函数中
Now in your BottomSheetFragment's constructor
私有CustomInterface回调;
private CustomInterface callback;
public SelectStartTimeSheet(CustomInterface callback){
this.callback=callback;
}
最后使用此回调对象设置日期
And at last use this callback object to set your date
callback.callbackMethod("your date");
您将在 callbackMethod
函数中的片段"或活动"中接收该日期.
and yout will recieve this date in your Fragment or Your Activity in callbackMethod
function.
这篇关于从“底部工作表"对话框片段中获取价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!