SHARE
TWEET

Untitled

a guest Jan 21st, 2020 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.digisata.sharedprefc.adapter
  2.  
  3. import android.content.Context
  4. import android.os.Bundle
  5. import android.view.LayoutInflater
  6. import android.view.View
  7. import android.view.ViewGroup
  8. import android.widget.TextView
  9. import android.widget.Toast
  10. import androidx.recyclerview.widget.RecyclerView
  11. import com.digisata.sharedprefc.R
  12. import com.digisata.sharedprefc.fragment.AddNoteFragment
  13. import com.digisata.sharedprefc.fragment.DetailNoteFragment
  14.  
  15. internal class NoteAdapter (
  16.     private val context: Context,
  17.     private val notes: MutableList<String>?
  18. //    private val onItemClick: (String) -> Unit
  19. ) :
  20.     RecyclerView.Adapter<NoteAdapter.MyViewHolder>(), View.OnClickListener {
  21.     override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
  22.         MyViewHolder(
  23.             LayoutInflater.from(
  24.                 context
  25.             ).inflate(R.layout.note_item, parent, false)
  26.         )
  27.  
  28.     override fun getItemCount() = notes!!.count()
  29.  
  30.     override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
  31.         holder.bind(notes!!.get(position))
  32.     }
  33.  
  34.     inner class MyViewHolder(itemView: View) :
  35.         RecyclerView.ViewHolder(itemView), View.OnClickListener {
  36.         val title = itemView.findViewById<TextView>(R.id.tvTitle)
  37.  
  38.         fun bind(title: String) {
  39.             this.title.text = title
  40.  
  41.             /*itemView.setOnClickListener {
  42.                 onItemClick(title)
  43.             }*/
  44.         }
  45.  
  46.         override fun onClick(view: View?) {
  47.             Toast.makeText(context, "dewa", Toast.LENGTH_LONG).show()
  48.  
  49.             /*val activity = view?.context
  50.             val detailNoteFragment = DetailNoteFragment()
  51.             val bundle = Bundle()
  52.             bundle.putString(AddNoteFragment.bundleKey, title.toString())
  53.             detailNoteFragment.arguments = bundle
  54.  
  55.             activity.fra*/
  56.         }
  57.     }
  58.  
  59.     override fun onClick(view: View?) {
  60.         Toast.makeText(context, "dewa", Toast.LENGTH_LONG).show()
  61.         /*onItemClick.invoke()
  62.         val activity = view?.context
  63.         val detailNoteFragment = DetailNoteFragment()
  64.         val bundle = Bundle()
  65.         bundle.putString(AddNoteFragment.bundleKey, title.toString())
  66.         detailNoteFragment.arguments = bundle
  67.  
  68.         activity.support*/
  69.     }
  70. }
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