Android购物车动态添加

public class AddView extends LinearLayout implements View.OnClickListener {
    private final TextView viewById;
    private final ImageView btn_jian;
    private final ImageView btn_add;


    int max_num=4;//最大值
    int min_num=0;//最小值
    int deful_num=0;//默认值

    /**
     * 通过默认值与最大值对比  设置默认值
     * @param context
     */

//    public AddView(Context context) {
//       this(context,null);
//    }
//
//    public AddView(Context context, AttributeSet attrs) {
//        this(context, null,0);
//    }

    public AddView(Context context, AttributeSet attrs) {
        super(context, attrs);
        View inflate = View.inflate(context, R.layout.addview, this);
         viewById = (TextView) inflate.findViewById(R.id.tv);
        btn_jian = ( ImageView) inflate.findViewById(R.id.btn_jian);
        btn_add = ( ImageView) inflate.findViewById(R.id.btn_add);
        int deful_num = getDeful_num();
        setDeful_num(deful_num);
        btn_add.setOnClickListener(this);
        btn_jian.setOnClickListener(this);
    }


    public void onClick(View view){
        switch (view.getId()){
            case R.id.btn_add:
               // Toast.makeText(getContext(), "----", Toast.LENGTH_SHORT).show();
                addNum(view);
                break;
            case R.id.btn_jian:
                //Toast.makeText(getContext(), "----", Toast.LENGTH_SHORT).show();
                addJian(view);
                break;
        }
    }

    private void addJian(View view) {

        if(deful_num>min_num){
             deful_num--;
        }
        setDeful_num(deful_num);
        if(OnListnerChanged!=null){
            OnListnerChanged.changedNum(deful_num);
        }
        deleteGoods(view);
    }

    private void addNum(View view) {

        if(deful_num

 

 

 

你可能感兴趣的:(Android)