[英]How to do modal bottom sheet dialog in recyclerview with kotlin
當我單擊 recyclerView 中的一個項目時,我希望打開模態底頁。 但我希望我在 recyclerView 中單擊的項目的葯物名稱出現在 bottom_sheet.xml 內文本中的葯物名稱中。
這是我的 recyclerViewAdapter:
class RecyclerViewAdapter(val mnArrayList: ArrayList<String>, val nmArrayList: ArrayList<String>): RecyclerView.Adapter<RecyclerViewAdapter.MyHolder>() {
class MyHolder(val binding: RecyclerRowBinding) : RecyclerView.ViewHolder(binding.root){
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyHolder {
val binding= RecyclerRowBinding.inflate(LayoutInflater.from(parent.context),parent,false)
return MyHolder(binding)
}
override fun onBindViewHolder(holder: MyHolder, position: Int) {
holder.binding.textViewMName.text= mnArrayList.get(position) //medicine name
holder.binding.textViewMAdet.text = nmArrayList.get(position) //medicine quantity
holder.itemView.setOnClickListener {
Toast.makeText(holder.itemView.context,"Clicked!",Toast.LENGTH_LONG).show()
val dialog = BottomSheetDialog(holder.itemView.context)
val view= LayoutInflater.from(holder.itemView.context).inflate(R.layout.bottom_sheet,null)
val textSheet= view.findViewById<TextView>(R.id.bottomSheetText)
textSheet.text= mnArrayList.get(position)
println(textSheet.toString())
dialog.show()
}
}
override fun getItemCount(): Int {
return mnArrayList.size
}
}
這是我的 bottom_sheet.xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/bottomSheetText"
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="medicine"
android:textSize="20sp"
android:textColor="@color/black"
android:gravity="center">
</TextView>
</LinearLayout>
我該怎么做呢?
您必須在此處為其指定特定位置的值(定義一個變量):
textSheet.text = mnArrayList.get(position)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.