package com.bawie.gouwuche.view.activity;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.bawie.gouwuche.R;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
/**
-
作者: 姓名
-
日期: 2019/9/7 14:15
*/
public class MyView extends LinearLayout {
@BindView(R.id.del)
Button del;
@BindView(R.id.text_num)
TextView textNum;
@BindView(R.id.jia)
Button jia;
int num;
public MyView(Context context, AttributeSet attrs) {
super(context, attrs);
LayoutInflater.from(context).inflate(R.layout.myview, this, true);
ButterKnife.bind(this);
}
public void setText(int count){
this.num = count;
textNum.setText(num+"");
}@OnClick({R.id.del, R.id.jia})
public void onClick(View view) {
switch (view.getId()) {
case R.id.del:
if (num < 1) {
Toast.makeText(getContext(), “不能再加了”, Toast.LENGTH_SHORT).show();
} else {
num–;
textNum.setText(num + “”);
if (setNum != null) {
setNum.nnm(num);
}
}
break;
case R.id.jia:
num++;
textNum.setText(num+"");
if (setNum!=null){
setNum.nnm(num);
}
break;}
}
public interface setNum{
void nnm(int num);
}
private setNum setNum;
public void setNumList(setNum setNum){
this.setNum=setNum;
}
}