将 Parent 视图发送到 child (BottomSheetDialogFragment)
Send Parent View to a child (BottomSheetDialogFragment)
今天我想知道是否可以这样做。我的意思是,当我加载 child 视图时发送 parent 视图。换句话说,我想在 child.
上处理 parent
Parent 查看
imgFilter.setOnClickListener {
MyDialogFragment().show(requireActivity().supportFragmentManager,"filter_dialog")
}
Child 查看
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
}
}
如果可能,我不会这样做,或者如果您有其他建议,我会在这里听取和学习。
非常感谢!
问题是 show
方法正在接收来自 activity 的片段管理器作为参数,因此它找不到父片段
MyDialogFragment().show(childFragmentManager, "filter_dialog")
应该允许 parentFragment?.view?
被发现。
今天我想知道是否可以这样做。我的意思是,当我加载 child 视图时发送 parent 视图。换句话说,我想在 child.
上处理 parentParent 查看
imgFilter.setOnClickListener {
MyDialogFragment().show(requireActivity().supportFragmentManager,"filter_dialog")
}
Child 查看
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
}
}
如果可能,我不会这样做,或者如果您有其他建议,我会在这里听取和学习。
非常感谢!
问题是 show
方法正在接收来自 activity 的片段管理器作为参数,因此它找不到父片段
MyDialogFragment().show(childFragmentManager, "filter_dialog")
应该允许 parentFragment?.view?
被发现。