分类购物车bean

app

package dongyushan.bwie.com.lianxi.app;

import com.facebook.drawee.backends.pipeline.Fresco;

public class Application extends android.app.Application {
    @Override
    public void onCreate() {
        super.onCreate();
        Fresco.initialize(this);
        
    }
}

 

 

 

layout

package dongyushan.bwie.com.lianxi.bean;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import dongyushan.bwie.com.lianxi.R;


public class NumberLayout extends LinearLayout implements View.OnClickListener {

    private TextView textLost;
    private TextView textShow;
    private TextView textAdd;

    public NumberLayout(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        View view = inflate(context, R.layout.number_layout, this);
        textLost = view.findViewById(R.id.text_lost);
        textShow = view.findViewById(R.id.text_show);
        textAdd = view.findViewById(R.id.text_add);

        textLost.setOnClickListener(this);
        textAdd.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.text_lost:
                int lostNum = Integer.parseInt(getTextShow());
                if (lostNum > 1) {
                    lostNum--;
                    setTextShow("" + lostNum);
                    if(listener != null){
                        listener.changeTakeNum(getTextShow());
                    }
                } else {
                    Toast.makeText(getContext(), "最小数量为1", Toast.LENGTH_SHORT).show();
                }
                break;
            case R.id.text_add:
                int addNum = Integer.parseInt(getTextShow());
                addNum++;
                setTextShow("" + addNum);
                if(listener != null){
                    listener.changeTakeNum(getTextShow());
                }
                break;
        }
    }

    public String getTextShow() {
        return textShow.getText().toString();
    }

    public void setTextShow(String num) {
        textShow.setText(num);
    }

    // 用于回调的接口
    public OnChangeNumListener listener;

    public interface OnChangeNumListener {
        void changeTakeNum(String str);
    }

    public void setListener(OnChangeNumListener listener) {
        this.listener = listener;
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值