Ledger Nano X - The secure hardware wallet
SHARE
TWEET

adapter

a guest Apr 8th, 2020 134 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.example.todo
  2.  
  3. import android.app.AlertDialog
  4. import android.content.DialogInterface
  5. import android.util.Log
  6. import android.view.LayoutInflater
  7. import android.view.View
  8. import android.view.ViewGroup
  9. import android.widget.Button
  10. import android.widget.TextView
  11. import android.widget.Toast
  12. import androidx.recyclerview.widget.RecyclerView
  13. import kotlinx.android.synthetic.main.list_item.view.*
  14.  
  15.  
  16. class TodoAdapter(private val myDataset: Model) : RecyclerView.Adapter<TodoAdapter.MyViewHolder>() {
  17.  
  18.     class MyViewHolder(val view: View) : RecyclerView.ViewHolder(view){
  19.         val todoText : TextView = itemView.todoText
  20.         val buttonDelete : Button = itemView.buttonHapus
  21.         val buttonEdit : Button = itemView.buttonEdit
  22.     }
  23.  
  24.     override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TodoAdapter.MyViewHolder {
  25.         var view = LayoutInflater.from(parent.context).inflate(R.layout.list_item, parent, false)
  26.         return MyViewHolder(view)
  27.     }
  28.  
  29.     // Replace the contents of a view (invoked by the layout manager)
  30.     override fun onBindViewHolder(holder: MyViewHolder, index: Int) {
  31.         holder.todoText.text = myDataset.data.value!![index].task
  32.  
  33.         //remove
  34.         holder.buttonDelete.setOnClickListener{ view->
  35.             myDataset.deleteTodo(holder.adapterPosition) // method from Model
  36.             notifyItemRemoved(index) // delete berdasarkan index pada tampilan
  37.             notifyItemRangeChanged(index,myDataset.data.value!!.size) // merubah index kembali
  38.         }
  39.  
  40.         //edit
  41.         holder.buttonEdit.setOnClickListener{ view->
  42.             val context  = holder.itemView.context
  43.             val inflater = LayoutInflater.from(context)
  44.             val view = inflater.inflate(R.layout.pop_up,null)
  45.  
  46.             // textclicked
  47.             val prevText:String = myDataset.data.value!![index].task // data sebelumnya g
  48.             val editText = view.findViewById<TextView>(R.id.editInput)
  49.             editText.text = prevText
  50.  
  51.             // dialot / Alert
  52.             val alertDialog = AlertDialog.Builder(context)
  53.             alertDialog
  54.                 .setView(view)
  55.                 .setPositiveButton("Update",DialogInterface.OnClickListener{ dialog,id ->
  56.                     myDataset.updateTodo(holder.adapterPosition, editText.text.toString())
  57.                     notifyDataSetChanged()
  58.                 })
  59.                 .show()
  60.         }
  61.     }
  62.  
  63.     // Return the size of your dataset (invoked by the layout manager)
  64.     override fun getItemCount() = myDataset.data.value!!.size
  65. }
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