如何在Kotlin中将可绘制图像添加到recyclerview imageview?

时间:2019-12-02 07:50:49

标签: android kotlin android-recyclerview recycler-adapter

我想将可绘制图像添加到recyclerview imageview。 可绘制图像资源:r_300_x_300_2.png,                         r_300_x_300_3.png,                         r_300_x_300_4.png

检查我的活动和recyclerviewadapter代码。 (阻止更多细节。) (防止更多细节。)(防止更多细节。)(防止更多细节。)(防止更多细节。)(防止更多细节。)(防止更多细节。)(防止更多细节。)(防止更多细节。)(防止更多细节更多详细信息。)(阻止更多详细信息。)(阻止更多详细信息。)(阻止更多详细信息。)(阻止更多详细信息。)

class HistoryItemDataVo(title: String, pointValue: Int) {

    var title: String = title
    var pointValue: Int = pointValue



}
class HistoryitemReclycerViewAdapter(private var activity: Activity, private var dataList: MutableList<HistoryItemDataVo>): RecyclerView.Adapter<HistoryitemReclycerViewAdapter.ViewHolder>() {


    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {

        val inflater = LayoutInflater.from(parent.context)
        return ViewHolderItem(inflater.inflate(R.layout.history_item_list, parent, false))
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {

        val data = dataList[position]

        var h = holder as ViewHolderItem
        h.titleText.text =data.title
        h.pointValueText.text = data.pointValue.toString() + "P"


    }


    override fun getItemCount(): Int = dataList.size

    open inner class ViewHolder(itemView: View) : androidx.recyclerview.widget.RecyclerView.ViewHolder(itemView)

    inner class ViewHolderItem(itemView: View): ViewHolder(itemView) {
        var titleText = itemView.findViewById(R.id.titleText) as TextView
        var pointValueText = itemView.findViewById(R.id.pointValueText) as TextView
        var imageView=itemView.findViewById(R.id.imageView)as ImageView

    }
}

```
{{1}}

0 个答案:

没有答案