[英]How to passed parament the imageView in class adapter, Kotlin
class AdapterPostagem ( val car: MutableList): RecyclerView.Adapter<AdapterPostagem.CarViewHolder>(){ class AdapterPostagem ( val car: MutableList): RecyclerView.Adapter<AdapterPostagem.CarViewHolder>(){
inner class CarViewHolder ( itemView: View ): RecyclerView.ViewHolder( itemView ) {
fun bind(car: Car) {
with(car) {
itemView.txtNameCar.text = nameCar
itemView.txtBrandCar.text = brandCar
//This line, in AndroidStudio not accept this formated
itemView.imgCar.imageView = imgCar
itemView.txtDescri.text = descCar
itemView.txtPrice.text = priceCar
itemView.txtYearsCar.text = yearCar
}
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CarViewHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.adapter_postagem, parent, false)
return CarViewHolder( view )
}
override fun getItemCount(): Int = car.size
override fun onBindViewHolder(holder: CarViewHolder, position: Int) {
holder.bind( car[position])
}
} }
If you have the image string, you need to use an image processing library for displaying your images in an image view.如果您有图像字符串,则需要使用图像处理库在图像视图中显示图像。 Some of the popular libraries are Coil , Glide and Picasso .一些流行的库是Coil 、 Glide和Picasso 。 A simple way to display your image, if you are using let's say Glide, would be一种显示图像的简单方法,如果您使用 Glide,将是
Glide.with(context).load(imgCar).into(itemView.imgCar)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.