听底纸对话框片段被解散并打开一个新片段

时间:2018-08-02 09:26:05

标签: android kotlin android-dialogfragment bottom-sheet dialogfragment

我有一个bottomsheetdialog片段,上面有2个按钮。我正在fragment1上打开它。在button1上单击,它应该关闭该对话框,而在单击button2上,它应该首先关闭该对话框,然后打开一个新的片段Fragment2。现在,我可以解雇并移至fragment2,但唯一的问题是两个动作同时发生。我希望对话框先关闭,然后再启动第二个片段。

enter image description here

我的代码:

片段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
}
}

0 个答案:

没有答案