-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdapter.kt
More file actions
39 lines (30 loc) · 1.09 KB
/
Adapter.kt
File metadata and controls
39 lines (30 loc) · 1.09 KB
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
package com.kedia.customswipelibrary
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
class Adapter(
private val context: Context,
private val list: MutableList<String>
): RecyclerView.Adapter<Adapter.CustomViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CustomViewHolder {
return CustomViewHolder(LayoutInflater.from(context).inflate(R.layout.ic_card, parent, false))
}
override fun getItemCount(): Int {
return list.size
}
override fun onBindViewHolder(holder: CustomViewHolder, position: Int) {
holder.bind(list[position])
}
fun removeItem(adapterPosition: Int) {
list.removeAt(adapterPosition)
}
inner class CustomViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
private var textView = itemView.findViewById<TextView>(R.id.textView)
fun bind(string: String) {
textView.text = string
}
}
}