daily pastebin goal
63%
SHARE
TWEET

Untitled

a guest Jan 20th, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package id.ihwan.aac.adapter
  2.  
  3. import android.content.Context
  4. import android.view.LayoutInflater
  5. import android.view.ViewGroup
  6. import androidx.databinding.DataBindingUtil
  7. import androidx.recyclerview.widget.RecyclerView
  8. import id.ihwan.aac.R
  9. import id.ihwan.aac.databinding.ItemMovieBinding
  10. import id.ihwan.aac.model.Movie
  11. import id.ihwan.aac.viewmodel.ItemMovieViewModel
  12.  
  13. class MainAdapter(val context: Context): RecyclerView.Adapter<MainAdapter.ViewHolder>() {
  14.  
  15.     protected var movies: MutableList<Movie> = mutableListOf()
  16.  
  17.     override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
  18.         val binding: ItemMovieBinding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.item_movie, parent, false)
  19.         return ViewHolder(binding)
  20.     }
  21.  
  22.     override fun getItemCount(): Int {
  23.         return movies.size
  24.     }
  25.  
  26.     override fun onBindViewHolder(holder: ViewHolder, position: Int) {
  27.         holder.bind(movies[holder.adapterPosition])
  28.     }
  29.  
  30.  
  31.     fun setData(movie: MutableList<Movie>){
  32.         this.movies = movie
  33.     }
  34.  
  35.     class ViewHolder(private val binding: ItemMovieBinding) : RecyclerView.ViewHolder(binding.root){
  36.         fun bind(model: Movie){
  37.             val viewModel = ItemMovieViewModel(model)
  38.             binding.itemMovie = viewModel
  39.  
  40.         }
  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