package com.njsoft.ace.shoppingCart.adapter;
import android.annotation.SuppressLint;
import android.graphics.drawable.GradientDrawable;
import android.support.v4.content.ContextCompat;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.njsoft.ace.R;
import java.util.List;
import java.util.Random;
public class PaymentSelectAdapter extends BaseQuickAdapter<String, BaseViewHolder> {
private int selectPosition = -1;
public PaymentSelectAdapter(int layoutResId, List<String> list) {
super(layoutResId, list);
}
/**
* 选择
*
* @param selectPosition 当前位置
*/
public void setSelectPosition(int selectPosition) {
this.selectPosition = selectPosition;
notifyDataSetChanged();
}
/**
* 删除某位置的数据
*/
public void deletePosition(int deletePosition) {
getData().remove(deletePosition);
notifyItemRemoved(deletePosition);
}
@Override
protected void convert(BaseViewHolder helper, String item) {
ImageView imageView = helper.getView(R.id.Card_Img);
RelativeLayout cardLayout = helper.getView(R.id.Card_Layout);
if (selectPosition == helper.getAdapterPosition()) {
imageView.setImageResource(R.mipmap.radiobutton);
} else {
imageView.setImageResource(R.mipmap.radiobutton_default);
}
//获取随机颜色
int colors[] = { getColor(), getColor()};
/**
*渐变的方向,颜色
**/
GradientDrawable gd = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, colors);
//设置圆角
gd.setCornerRadius(20);
//设置背景
cardLayout.setBackground(gd);
}
//获取随机颜色
private int getColor() {
Random random = new Random();
return 0xff000000 | random.nextInt(0x00ffffff);
}
}
网友评论