1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| package com.example.ContactActivity
import android.content.Context
import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.notekotlincours1.R
class NoteRecyclerAdapter (private val context: Context, private val notes: List<ContactNote>): RecyclerView.Adapter<NoteRecyclerAdapter.ViewHolder>() {
private val layoutInflater = LayoutInflater.from(context)
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val itemView = layoutInflater.inflate(R.layout.item_list_note, parent, false)
return ViewHolder(itemView)
}
override fun getItemCount() = notes.size
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val note = notes[position]
holder.textCours.text = note.contactInfo?.titreProf
holder.textTitre.text = note.Commentaire
holder.notePosition = position
}
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView){
val textCours = itemView.findViewById<TextView>(R.id.textCours)
val textTitre = itemView.findViewById<TextView>(R.id.textTitre)
var notePosition = 0
init {
itemView?.setOnClickListener {
val intent = Intent(context, MainActivity::class.java)
intent.putExtra(EXTRA_NOTE_POSITION, notePosition)
context.startActivity(intent)
}
}
}
} |
Partager