我有一个bottomsheetdialog片段,上面有2个按钮。我正在fragment1
上打开它。在button1
上单击,它应该关闭该对话框,而在单击button2
上,它应该首先关闭该对话框,然后打开一个新的片段Fragment2
。现在,我可以解雇并移至fragment2
,但唯一的问题是两个动作同时发生。我希望对话框先关闭,然后再启动第二个片段。
我的代码:
片段1:
private var button2ClickListner = object : AcknowledgmentDialogFragment.AcknowledgmentCTAAction {
override fun onContinueClick() {
initializeFragment2()
}
}
private fun showAcknowledgment() {
AcknowledgmentDialogFragment = AcknowledgmentDialogFragment().newInstance(button2ClickListner)
AcknowledgmentDialogFragment.show(fragmentManager, AcknowledgmentDialogFragment.tag)
}
AcknowledgmentDialogFragment
class AcknowledgmentDialogFragment : BottomSheetDialogFragment() {
private lateinit var binding: BottomsheetLayoutAcknowledgmentBinding
interface AcknowledgmentCTAAction {
fun onContinueClick()
}
private lateinit var btn2: AcknowledgmentCTAAction
fun newInstance(btnContinue: AcknowledgmentCTAAction): AcknowledgmentDialogFragment {
this.btn2 = btn2
return this
}
private fun subscribeForUiEvents() {
binding.button1.setOnClickListener({
dismiss()
})
binding.button2.setOnClickListener({
dismiss()
btn2.onContinueClick()
})
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
binding = DataBindingUtil.inflate(inflater, R.layout.bottomsheet_layout_acknowledgment, container, false)
subscribeForUiEvents()
return binding.root
}
override fun onActivityCreated(arg0: Bundle?) {
super.onActivityCreated(arg0)
dialog.window.decorView.findViewById<View>(android.support.design.R.id.touch_outside).setOnClickListener(null)
dialog.window.attributes.windowAnimations = R.style.DialogAnimation
}
}