so I want to have a onclicklistener
for my RecyclerView
in Android but I am not sure how I should do that.
I have a CustomAdapterClass
for my Workoutlist
that looks like this:
class CustomAdapter(val workoutList: ArrayList<workout>) : RecyclerView.Adapter<CustomAdapter.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CustomAdapter.ViewHolder {
val v = LayoutInflater.from(parent.context).inflate(R.layout.list_layout, parent, false)
return ViewHolder(v)
}
override fun onBindViewHolder(holder: CustomAdapter.ViewHolder, position: Int) {
holder.bindItems(workoutList[position])
}
override fun getItemCount(): Int {
return workoutList.size
}
class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
fun bindItems(workout: workout) {
val cardDate = itemView.findViewById<TextView>(R.id.cardDate)
val cardDescription = itemView.findViewById<TextView>(R.id.cardDescription)
cardDate.text = workout.date
cardDescription.text = workout.description
}
}
}
And I push my workouts in like this (in my Main Activity
):
val recyclerView = findViewById<RecyclerView>(R.id.RecyclerView)
recyclerView.layoutManager = GridLayoutManager(this, 3)
val workouts = ArrayList<workout>()
workouts.add(workout("12.09.2018", "Kniebeugen und Bizeps + Rücken"))
workouts.add(workout("12.09.2018", "Kniebeugen und Bizeps + Rücken"))
workouts.add(workout("12.09.2018", "Kniebeugen und Bizeps + Rücken"))
workouts.add(workout("12.09.2018", "Kniebeugen und Bizeps + Rücken"))
workouts.add(workout("12.09.2018", "Kniebeugen und Bizeps + Rücken"))
workouts.add(workout("12.09.2018", "Kniebeugen und Bizeps + Rücken"))
workouts.add(workout("12.09.2018", "Kniebeugen und Bizeps + Rücken"))
workouts.add(workout("12.09.2018", "Kniebeugen und Bizeps + Rücken"))
val adapter = CustomAdapter(workouts)
recyclerView.adapter = adapter
I would like to make my workouts clickable and so I can use the name and the description from the workout to open a new activity with them as the intention.
Any help is appreciated!
I do not get where he put that extension in the "duplicate"