java - 从 RecyclerView 适配器获取 BottomSheetDialogFragment 中的视图
问题描述
我有一个RecyclerView
. 此视图的每个单元格RecyclerView
都有一个按钮,可以BottomSheetDialogFragment
从Adapter
.
从我的电话中调用时,底部的表格确实会显示并正确关闭Adapter
我希望能够通过点击我的BottomSheetDialogFragment
.
这是我BottomSheetDialogFragment
课堂上的按钮
<Button
android:id="@+id/deleteBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Delete" />
这是我onBindViewHolder()
找不到从那里访问 deleteBtn 的方法,BottomSheetDialogFragment
因此我可以继续删除我的单元格
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()
解决方案
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
}
}
}
推荐阅读
- api - 使用基于 Acumatica 合同的 SOAP API 添加采购订单行
- python - 当鼠标不动时 Pygame 窗口冻结
- markdown - 降价:3张不同尺寸的图片
- python-3.x - 如何让我在本地运行的代码订阅来自远程运行的相同代码的通知?
- python - 如何使用正则表达式删除带有数字的特定单词模式?
- spring-boot - 如何在 Spring Boot 中编写 CompletableFuture supplyAsync(在 for 循环中调用)?
- java - Java TimeTask 取消后继续程序
- android - 如何将位图从画廊插入和读取到房间数据库
- python - 带有远程/服务器连接的 Python 上的 Bloomberg blpapi
- elasticsearch - 我们如何在 Logstash 中合并不同的事件