SHARE
TWEET

Untitled

a guest Nov 19th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.example.android.trackmysleepquality.sleeptracker
  2.  
  3. import android.view.LayoutInflater
  4. import android.view.ViewGroup
  5. import android.widget.TextView
  6. import androidx.recyclerview.widget.RecyclerView
  7. import com.example.android.trackmysleepquality.R
  8. import com.example.android.trackmysleepquality.TextItemViewHolder
  9. import com.example.android.trackmysleepquality.database.SleepNight
  10.  
  11. class SleepNightAdapter : RecyclerView.Adapter<TextItemViewHolder>() {
  12.  
  13.     var data = listOf<SleepNight>()
  14.     set(value) {
  15.         field = value
  16.         notifyDataSetChanged()
  17.     }
  18.  
  19.     override fun getItemCount() = data.size
  20.  
  21.     override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TextItemViewHolder {
  22.         val layoutInflater = LayoutInflater.from(parent.context)
  23.         val view = layoutInflater.inflate(
  24.                 R.layout.text_item_view,
  25.                 parent,
  26.                 false) as TextView
  27.         return TextItemViewHolder(view)
  28.     }
  29.  
  30.  
  31.     override fun onBindViewHolder(holder: TextItemViewHolder, position: Int) {
  32.         val item = data[position]
  33.         holder.textView.text = item.sleepQuality.toString()
  34.     }
  35.  
  36. }
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