我正在RecyclerView
中显示数据。当我单击启动BottomSheetDialogFragment
的列表项时。
如何将列表项数据传递到Kotlin中的BottomSheetDialogFragment
BottomSheetFragment().show(context!!.supportFragmentManager, "BottomSheetFragment")
class BottomSheetFragment() : BottomSheetDialogFragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
var view = inflater.inflate(R.layout.coin_detail_lauout, container, false)
return view
}
}
答案 0 :(得分:0)
使用Bundle
val bottomSheetFragment = BottomSheetFragment()
val bundle = Bundle()
bundle.putString("key", data)
bottomSheetFragment.arguments = bundle
在ViewHolder
班上
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val textView = itemView.textView!!
init {
itemView.setOnClickListener {
showBottomSheet(itemView.context, list.get(layoutPosition))
}
}
private fun showBottomSheet(context: Context, data: String) {
val bottomSheetFragment = BottomSheetFragment()
val bundle = Bundle()
bundle.putString("key", data)
bottomSheetFragment.arguments = bundle
bottomSheetFragment.show(
(context as AppCompatActivity).supportFragmentManager,
"bottomSheetFragment"
)
}
}
在onCreateView
的{{1}}内部
BottomSheetFragment
arguments?.getString("key")
类
BottomSheetFragment