-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathPagingAdapter.kt
33 lines (26 loc) · 1.16 KB
/
PagingAdapter.kt
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
package com.ocnyang.recyclerviewevent.paging3
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.paging.PagingDataAdapter
import androidx.recyclerview.widget.RecyclerView
import com.ocnyang.recyclerviewevent.R
class PagingAdapter(val context: Context) :
PagingDataAdapter<PagingFruitBean, PagingViewHolder>(PagingAdapterDiffCallback()) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PagingViewHolder =
PagingViewHolder(
LayoutInflater.from(context).inflate(R.layout.activity_diff_util_item, parent, false)
)
override fun onBindViewHolder(holder: PagingViewHolder, position: Int) {
val itemBean = getItem(position)
holder.ivImg.setImageResource(itemBean?.imgId ?: R.drawable.ic_fruit_icons_01)
holder.tvTitle.text = itemBean?.fruitName ?: ""
}
}
class PagingViewHolder(view: View) : RecyclerView.ViewHolder(view) {
var ivImg: ImageView = itemView.findViewById(R.id.iv_img)
var tvTitle: TextView = itemView.findViewById(R.id.tv_title)
}