package com.example.testes import android.content.Context import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.ImageView import android.widget.TextView import androidx.core.content.ContextCompat.getDrawable import androidx.recyclerview.widget.RecyclerView import com.bumptech.glide.Glide class ImageGridAdapter(val imageList: List) : RecyclerView.Adapter() { lateinit var context: Context; /* Creates and inflates view and return FlowerViewHolder. */ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { context = parent.context; val view = LayoutInflater.from(parent.context) .inflate(R.layout.image_grid_item, parent, false) return ViewHolder(view) } /* Gets current flower and uses it to bind view. */ override fun onBindViewHolder(holder: ViewHolder, position: Int) { Glide.with(context) .load(imageList[position].preview_url) .placeholder(getDrawable(context, R.drawable.ic_launcher_foreground)) .into(holder.imageview) } inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { var imageview: ImageView = itemView.findViewById(R.id.image) } override fun getItemCount(): Int = imageList.size }