今天和大家分享一个非常好用的适配器,在Recyclerview,ListView,GridView里都可以适用:
第一步:添加依赖
implementation
'com.github.CymChad:BaseRecyclerViewAdapterHelper:3.0.4'
第二步:添加布局
<?xml version
="1.0" encoding
="utf-8"?>
<LinearLayout xmlns
:android
="http://schemas.android.com/apk/res/android"
android
:layout_width
="wrap_content"
android
:layout_height
="wrap_content"
android
:background
="@color/white"
android
:orientation
="vertical">
<ImageView
android
:id
="@+id/ima_photo"
android
:layout_width
="60dp"
android
:layout_height
="60dp"
android
:layout_marginLeft
="5dp"
android
:layout_marginTop
="@dimen/dp_10"
android
:layout_marginBottom
="@dimen/dp_10"
android
:scaleType
="fitXY" />
</LinearLayout
>
第三步:填充数据
class ImaPathAdapter : BaseQuickAdapter
<String, BaseViewHolder>(R
.layout
.item_ima
) {
override fun
convert(holder
: BaseViewHolder
, item
: String
) {
Glide
.with(context
).load(item
).into(holder
.getView(R
.id
.ima_photo
))
}
}
第四步:初始化使用
private var mAdapter
= ImaPathAdapter()
recycler_view
.adapter
= adapter
mAdapter
.setNewData(data
)
第五步:adapter
mAdapter
.setOnItemClickListener
{ _
, _
, position
->
}
注:Recyclerview的点击使用
转载请注明原文地址:https://tech.qufami.com/read-24367.html