SHARE
TWEET

Untitled

a guest Dec 11th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class RecyclerViewAdapter(private val context: Context, private val items: List<Item>, private val listener: (Item) -> Unit)
  2.     : RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder>() {
  3.  
  4.     override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
  5.         ViewHolder(LayoutInflater.from(context).inflate(R.layout.item_list, parent, false))
  6.  
  7.     override fun onBindViewHolder(holder: ViewHolder, position: Int) {
  8.         holder.bindItem(items[position], listener)
  9.     }
  10.  
  11.     override fun getItemCount(): Int = items.size
  12.  
  13.     class ViewHolder(override val containerView: View) : RecyclerView.ViewHolder(containerView), LayoutContainer{
  14.  
  15.         fun bindItem(items: Item, listener: (Item) -> Unit) {
  16.             itemView.name.text = items.name
  17.             items.image?.let { Picasso.get().load(it).into(itemView.image) }
  18.             itemView.setOnClickListener {
  19.                 listener(items)
  20.             }
  21.         }
  22.     }
  23. }
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