recyclerview实现单选多选全选反选

业务代码中的选择工具类,一个简单的recyclerAdapter

Quick Setup

dependencies {
	 implementation 'com.joketng:choseutil:1.0.1'
}

Usage

Add RecyclerView to your layout

    <android.support.v7.widget.RecyclerView
            android:id="@+id/rv_chose"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            />

Add LayoutManager

    rv_chose.layoutManager = LinearLayoutManager(context)
    //or set other LayoutManager
    

then set recyclerAdapter

choseAdapter = object :ChoseAdapter<MyChoseBean>(this, listContent){
            override fun bindData(holder: MyViewHolder) {
                holder.itemView.tv_text.text = listContent[holder.layoutPosition].title
            }

            override fun createCustomView(layout: LinearLayout) {
                LayoutInflater.from(context).inflate(R.layout.item_custom, layout, true)
            }
        }.setOnNotSelectedListener {
            it.itemView.img_check.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.vector_drawable_check_box_off))
        }.setOnIsSelectedListener {
            it.itemView.img_check.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.vector_drawable_check_box_on))
        }.setOnClickListener {
//            Toast.makeText(context,"${it.adapterPosition}",Toast.LENGTH_SHORT).show()
        }.setSingleChose(false)

在createCustomView()方法中添加列表自定义布局文件,在bindData()方法中绑定数据到控件,setOnNotSelectedListener()方法控制没有选中时控件的显示方式,setOnIsSelectedListener()方法控制选中状态下控件的显示方式

传送门 Github Demo

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值