SHARE
TWEET

RecyclerView Mode List

chappie00 Sep 21st, 2019 112 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import android.view.LayoutInflater
  2. import android.view.View
  3. import android.view.ViewGroup
  4. import android.widget.ImageView
  5. import android.widget.TextView
  6. import androidx.appcompat.view.menu.ActionMenuItemView
  7. import androidx.recyclerview.widget.RecyclerView
  8. import com.bumptech.glide.Glide
  9. import com.bumptech.glide.request.RequestOptions
  10.  
  11. class ListHeroAdapter(private val listHero: ArrayList<Hero>) : RecyclerView.Adapter<ListHeroAdapter.ListViewHolder>() {
  12.     override fun onCreateViewHolder(viewGroup: ViewGroup, i: Int): ListViewHolder {
  13.         val view: View = LayoutInflater.from(viewGroup.context).inflate(R.layout.item_row_hero, viewGroup, false)
  14.         return ListViewHolder(view)
  15.     }
  16.  
  17.     override fun onBindViewHolder(holder: ListViewHolder, position: Int) {
  18.         val hero = listHero[position]
  19.  
  20.         Glide.with(holder.itemView.context)
  21.             .load(hero.photo)
  22.             .apply(RequestOptions().override(55, 55))
  23.             .into(holder.imgPhoto)
  24.  
  25.         holder.tvName.text = hero.name
  26.         holder.tvDetail.text = hero.detail
  27.  
  28.         holder.itemView.setOnClickListener { onItemClickCallback.onItemClicked(listHero[holder.adapterPosition])}
  29.     }
  30.  
  31.     override fun getItemCount(): Int {
  32.         return listHero.size
  33.     }
  34.  
  35.  
  36.  
  37.     inner class ListViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
  38.         var tvName: TextView = itemView.findViewById(R.id.tv_item_name)
  39.         var tvDetail: TextView = itemView.findViewById(R.id.tv_item_detail)
  40.         var imgPhoto: ImageView = itemView.findViewById(R.id.img_item_photo)
  41.     }
  42. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top