【问题标题】:Send Parent View to a child (BottomSheetDialogFragment)将父视图发送给孩子 (BottomSheetDialogFragment)
【发布时间】:2020-11-20 18:59:42
【问题描述】:

今天我想知道是否有可能做到这一点。我的意思是,当我加载子视图时发送父视图。换句话说,当我在孩子身上时,我想处理父母。

父视图

  imgFilter.setOnClickListener {
            MyDialogFragment().show(requireActivity().supportFragmentManager,"filter_dialog")
        }

子视图

class MyDialogFragment : BottomSheetDialogFragment() {
    override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
    val dialog = super.onCreateDialog(savedInstanceState) as BottomSheetDialog

    val view = View.inflate(context, R.layout.filter_sheet_layout, null)

    val linearLayout = view.findViewById<LinearLayout>(R.id.root)
    val params = linearLayout.layoutParams as LinearLayout.LayoutParams
    params.height = getScreenHeight()
    linearLayout.layoutParams = params

    backArrowClick(view)
    hideKeyboard()


    dialog.setContentView(view)
    mBehavior = BottomSheetBehavior.from(view.parent as View)

    parentFragment?.view?.findViewById<TextView>(R.id.name_store)?.text = "Hello World"

    return dialog
}
}

如果有可能,我不知道,或者如果您有其他建议,我会在这里听取和学习。

非常感谢!

【问题讨论】:

  • parentFragment?.view是你需要的吗?
  • parentFragment = null :c
  • 试试MyDialogFragment().show(childFragmentManager, "filter_dialog")
  • 非常感谢你让我度过了愉快的一天
  • 是否愿意通过对答案的投票来回馈支持?

标签: kotlin bottom-sheet android-bottomsheetdialog bottomsheetdialogfragment


【解决方案1】:

问题是show 方法从活动中接收片段管理器作为参数,因此它无法找到父片段

MyDialogFragment().show(childFragmentManager, "filter_dialog")

应该允许parentFragment?.view?被发现。

【讨论】:

    猜你喜欢
    • 2022-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-28
    相关资源
    最近更新 更多