0

I have a adapter and within this adapter class, I have Viewholder inner class. From this Viewholder I want to share the clicked item data to the bottomsheetdialogfragment.

Here is my Code for the adapter viewholder:

inner class MedicineFeelingViewHolder(v: View) : RecyclerView.ViewHolder(v), View.OnClickListener {
        private var view: View = v
        var medicineImage: ImageView? = null
        var medicineName: TextView? = null

        init {
            v.setOnClickListener(this)
            medicineImage = v.findViewById(R.id.medicine_image)
            medicineName = v.findViewById(R.id.medicine_name)
        }


        override fun onClick(v: View?) {
            val itemPosition = layoutPosition

            Toast.makeText(v!!.context, "You have chosen "+medicineFeeling[itemPosition].medicineName, Toast.LENGTH_SHORT).show()
        }

    }

Is it possible to share the clicked data to my bottomsheetdialogfragment?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Seyfullah
  • 68
  • 7

1 Answers1

0

Yes its possible.

Most probably you are going to open to bottomsheetdialogfragment from the same activity which holds the recycler view. So what you need to do is pass a listener to the adapter while initialising the adapter. And then on click event call the listener. As the listener is implemented in the activity it can open the bottomsheetdialogfragment with value passed to listener through the click event.

You can checkout this link to see how to pass a listener to an adapter. Let me know if you don't understand any part. Happy Coding!

Md Golam Rahman Tushar
  • 2,175
  • 1
  • 14
  • 29