实现构造方法:constructor
class HomeFunctionAdapter: BaseQuickAdapter<HomeFunctionInfo,BaseViewHolder> {
constructor(data:List<HomeFunctionInfo>):super(R.layout.item_home_function, data)
override fun convert(helper: BaseViewHolder, item: HomeFunctionInfo?) {
val layout_item = helper.getView<RelativeLayout>(R.id.home_function_layout_item)
val img = helper.getView<ImageView>(R.id.home_function_img)
val tv_name = helper.getView<TextView>(R.id.home_function_tv_name)
val tv_desc = helper.getView<TextView>(R.id.home_function_tv_desc)
val tv_paste = helper.getView<TextView>(R.id.home_function_tv_paste)
val tv_hint = helper.getView<TextView>(R.id.home_function_tv_paste_hint)
img.background = mContext.getDrawable(R.mipmap.ic_input_text)
tv_name.setText(item?.name)
tv_desc.setText(item?.desc)
tv_paste.setText(item?.url)
tv_hint.setText(item?.urHint)
layout_item.setOnClickListener {
when(helper.adapterPosition){
0 -> mContext.startActivity(Intent(mContext,SecondActivity::class.java))
1 -> mContext.startActivity(Intent(mContext,SecondActivity::class.java))
}
}
}
}
recycleview初始化:
adapter_function=HomeFunctionAdapter(list_function!!)
recycle_function?.layoutManager=GridLayoutManager(mContext,2)
recycle_function?.adapter=adapter_function