[英]Getting views inside BottomSheetDialogFragment from a RecyclerView adapter
我有一个RecyclerView
。 这个RecyclerView
视图的每个单元都有一个按钮,该按钮从Adapter
内调用BottomSheetDialogFragment
。
从Adapter
调用底页时,底页确实显示并正确关闭
我希望能够通过点击BottomSheetDialogFragment
的按钮来删除单元格。
这是我的BottomSheetDialogFragment
类中的按钮
<Button
android:id="@+id/deleteBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Delete" />
这是我的onBindViewHolder()
,在这里我找不到从BottomSheetDialogFragment
访问deleteBtn的方法,所以我可以继续删除单元格
override fun onBindViewHolder(holder: SavesAdapterHolder, position: Int) {
val bottomSheet: BottomSheetDialogFragment = mBottomSheet()
bottomSheet.setStyle(DialogFragment.STYLE_NORMAL, R.style.BottomDialogTheme)
val myActivity = (context as FragmentActivity).supportFragmentManager
holder.openButton.setOnClickListener {
bottomSheet.show(myActivity, "bottomSheet $position")
}
}
任何人都可以onBindViewHolder()
向我onBindViewHolder()
如何从onBindViewHolder()
内部访问删除按钮的正确方向
BottomSheet视图应该可以通过getView()方法访问
override fun onBindViewHolder(holder: SavesAdapterHolder, position: Int) {
val bottomSheet: BottomSheetDialogFragment = mBottomSheet()
bottomSheet.setStyle(DialogFragment.STYLE_NORMAL, R.style.BottomDialogTheme)
val myActivity = (context as FragmentActivity).supportFragmentManager
holder.openButton.setOnClickListener {
bottomSheet.show(myActivity, "bottomSheet $position")
// execute the commited transaction before trying to access the view
myActivity.executePendingTransactions()
// accessing button view
bottomSheet.view?.findViewById("*your_btn_id*").setOnClickListener{
//you can remove item here and notify data set
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.