Skip to content

Instantly share code, notes, and snippets.

@aligkts
Created May 8, 2020 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aligkts/22ce11c50ccf3582873070b99612248d to your computer and use it in GitHub Desktop.
Save aligkts/22ce11c50ccf3582873070b99612248d to your computer and use it in GitHub Desktop.
class ImageAdapter(private val image: Image) : RecyclerView.Adapter<ImageAdapter.DataViewHolder>() {
class DataViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
fun bind(image: Image) {
itemView.img_item.setImageResource(image.image)
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
DataViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_image, parent, false))
override fun getItemCount(): Int = 1
override fun onBindViewHolder(holder: DataViewHolder, position: Int) =
holder.bind(image)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment