PolicyFieldAdapter.kt
1.56 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
40
41
42
43
44
45
46
47
48
49
package com.example.vip
import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.item_policyfield.view.*
class PolicyFieldAdapter(private val items: ArrayList<PolicyFieldItem>) :
RecyclerView.Adapter<PolicyFieldAdapter.ViewHolder>() {
override fun getItemCount() = items.size
override fun onBindViewHolder(holder: PolicyFieldAdapter.ViewHolder, position: Int) {
val item = items[position]
holder.apply {
bind(item)
itemView.tag = item
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int):
PolicyFieldAdapter.ViewHolder {
val inflatedView = LayoutInflater.from(parent.context)
.inflate(R.layout.item_policyfield, parent, false)
return PolicyFieldAdapter.ViewHolder(inflatedView)
}
class ViewHolder(v: View) : RecyclerView.ViewHolder(v) {
private var view: View = v
fun bind(item: PolicyFieldItem) {
view.fieldIcon.setImageDrawable(item.policyFieldItemImage)
view.fieldIconText.text = item.policyFieldItemText
view.setOnClickListener{
val intent=Intent(view.context, RecommendActivity::class.java)
//putExtraStart
intent.putExtra("key",item.policyFieldItemText)
//putExtraEnd
view.context.startActivity(intent)
}
}
}
}