recyclerview 实现单选/多选

首先声明:    int mPosition=-1;

Adapter :

mAdapter=new CommonAdapter(ChooiseBZAty.this,R.layout.rv_chooise_item,listData) {

@Override

    protected void convert(ViewHolder holder, currency msg, int position) {

holder.setText(R.id.tv_chooise_name,msg.getSymbol());

        holder.setOnClickListener(R.id.ll_chooise_layout, new View.OnClickListener() {

@Override

            public void onClick(View v) {

                mPosition =position;

                notifyDataSetChanged();

            }

});

        if (mPosition != position) {

holder.setVisible(R.id.img_chooise,false);

        }else if (mPosition == position) {

holder.setVisible(R.id.img_chooise,true);

            holder.setImageResource(R.id.img_chooise,R.mipmap.icon_zhugongn_1);

        }

}

};


//////////////////////////////////////////////////////////////////////////////////////    多选    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////

private ListcheckLableShop =new ArrayList<>();


if (checkLableShop.contains(results.getId())) {

holder.setBackgroundRes(R.id.tv_item_name, R.drawable.dbg_gray_blue_43);

    holder.setTextColor(R.id.tv_item_name, Color.parseColor("#57A8FF"));

}else {

holder.setBackgroundRes(R.id.tv_item_name, R.drawable.dbg_order_label_43);

    holder.setTextColor(R.id.tv_item_name, Color.parseColor("#999999"));

}

holder.setOnClickListener(R.id.tv_item_name, new View.OnClickListener() {

@Override

    public void onClick(View v) {

if(checkLableShop.contains(results.getId())){

checkLableShop.remove(results.getId());

        }else {

checkLableShop.add(results.getId());

        }

mAdapterRider.notifyDataSetChanged();

    }

});

你可能感兴趣的:(recyclerview 实现单选/多选)