package com.bawie.weidu.cart;
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.weidu.R;
/**
-
@Author:asus
-
@E-mail: 945574298@163.com
-
@Date:2019/4/26 15:48
-
@Description:描述信息
*/
public class Addandsub extends LinearLayout {private Button add;
private Button jian;
private TextView num;
private int nums=1;
NumCallBack numCallBack;public interface NumCallBack{
void getNum(int nums);
}public void setNumCallBack(NumCallBack numCallBack) {
this.numCallBack = numCallBack;
}public Addandsub(Context context) {
super(context);
}public Addandsub(Context context,AttributeSet attrs) {
super(context, attrs);
initView(context);
}public Addandsub(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}private void initView(final Context context) {
View inflate = LayoutInflater.from(context).inflate(R.layout.addandjian, null,false); addView(inflate); add = findViewById(R.id.a_add); jian = findViewById(R.id.a_jian); num = findViewById(R.id.a_num); num.setText(nums+""); jian.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if(nums==1){ Toast.makeText(context,"数量不能少于1",Toast.LENGTH_LONG).show(); return; } else{ nums--; num.setText(nums+""); numCallBack.getNum(nums); } } }); add.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { nums++; num.setText(nums+""); numCallBack.getNum(nums); } });
}
}