侧滑置顶,取消置顶

第一步:布局




    

        

        

        


        


        

        

        


    


    

        
    

第二步:适配器

class TeamItemAdapter(var list: ArrayList?) :
    BaseQuickAdapter(R.layout.item_team_member, list) {

    override fun convert(holder: BaseViewHolder, item: TeamListBean) {
        holder.setText(R.id.tv_team_name_short, CommonUtils.getBeforeTwoStr(item.teamName))
        holder.setText(R.id.tv_team_name, item.teamName)
        holder.setText(R.id.tv_takephots_peoples, "已xx数:2")
        holder.setGone(R.id.tv_top_tips, !item.topFlag)
        holder.setText(R.id.tv_pic_num, "照片:2")
        when (item.roleType) {
            1 -> {
                holder.setText(R.id.tv_admin, "主管理员")
                holder.setTextColor(
                    R.id.tv_admin,
                    AppContext.appContext.resources.getColor(R.color.color_ff615d)
                )
                holder.setBackgroundResource(R.id.tv_admin, R.drawable.bg_ff615d_2radius)
            }
            2 -> {
                holder.setText(R.id.tv_admin, "管理员")
                holder.setTextColor(
                    R.id.tv_admin,
                    AppContext.appContext.resources.getColor(R.color.color_f2a649)
                )
                holder.setBackgroundResource(R.id.tv_admin, R.drawable.bg_1af2a649_2radius)
            }
            3 -> {
                holder.setText(R.id.tv_admin, "成员")
                holder.setTextColor(
                    R.id.tv_admin,
                    AppContext.appContext.resources.getColor(R.color.font_39ba81)
                )
                holder.setBackgroundResource(R.id.tv_admin, R.drawable.bg_39ba81_2radius)
            }
        }
        var tvTop = holder.getView(R.id.tv_top)
        tvTop.text = if (item.topFlag) {
            "取消置顶"
        } else {
            "置顶"
        }
        if (item.topFlag) {
            holder.setBackgroundColor(
                R.id.ll_top,
                AppContext.appContext.resources.getColor(R.color.color_ff615d)
            )
        } else {
            holder.setBackgroundColor(
                R.id.ll_top,
                AppContext.appContext.resources.getColor(R.color.font_c9cdd4)
            )
        }
    }
}

第三步:代码

mTeamAdapter.addChildClickViewIds(R.id.tv_top, R.id.cst_out)
mTeamAdapter.setOnItemChildClickListener { adapter, view, position ->
    val bean = adapter.data[position] as TeamListBean
    when (view.id) {
        R.id.tv_top -> {
            bean.topFlag = !bean.topFlag
      adapter.notification
        }

        R.id.cst_out -> {
           
        }
    }

}

你可能感兴趣的:(android-studio,kotlin,android)