[英]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.