Thursday, 29 August 2024

View Image url from api to ImageView in RecyclerView Adapter class

1. PhotoAdapter.kt

override fun onBindViewHolder(holder: PhotoViewHolder, position: Int) {
val photoList = photoResponceItem[position]
holder.title.text = photoList.title
holder.id.text = photoList.id.toString()
Glide
.with(holder.imageView)
.load(photoList.thumbnailUrl)
.centerCrop()
.into(holder.imageView);
}
inner class PhotoViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val title: TextView = itemView.findViewById(R.id.title)
val imageView: ImageView =itemView.findViewById(R.id.imageView)
}
2. build.gradle.kts
dependencies{
//image  loader
implementation(libs.androidx.glide.bumptech)
}
plugins {
id("org.jetbrains.kotlin.kapt")
}
3. libs.version.toml
androidx-glide-bumptech={group="com.github.bumptech.glide",name="glide",version="4.16.0"}

No comments:

Post a Comment