Created
March 22, 2018 20:40
-
-
Save chrisblakely01/3ca0d346603226b7c76a81f252aa6ce6 to your computer and use it in GitHub Desktop.
Adding an onclick listener to a recyclerview item
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun onBindViewHolder(holder: MyViewHolder, position: Int) { | |
val category = categoryList[position] | |
// Set height of cardview based on screen width | |
val displayMetrics = context.resources.displayMetrics | |
val finalHeight = displayMetrics.widthPixels / 2 | |
holder.cardView.layoutParams.height = finalHeight | |
holder.categoryName.text = category.oc | |
holder.categoryPhoto.loadUrl(category.icon) | |
holder.categoryPhoto.setOnClickListener { view -> | |
// categoryPhoto clicked. | |
// start your activity here | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment