private EditText count;
private TextView add;
private TextView sub;
private TextView add;
private TextView sub;
public AddSubView(Context context) {
this(context,null);
}
this(context,null);
}
public AddSubView(Context context, @Nullable AttributeSet attrs) {
this(context, attrs,0);
}
this(context, attrs,0);
}
public AddSubView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
View inflate = View.inflate(context, R.layout.layout_add, this);
sub= inflate.findViewById(R.id.sub);
add = inflate.findViewById(R.id.add);
count = inflate.findViewById(R.id.count);
sub.setOnClickListener(this);
add.setOnClickListener(this);
super(context, attrs, defStyleAttr);
View inflate = View.inflate(context, R.layout.layout_add, this);
sub= inflate.findViewById(R.id.sub);
add = inflate.findViewById(R.id.add);
count = inflate.findViewById(R.id.count);
sub.setOnClickListener(this);
add.setOnClickListener(this);
}
@Override
public void onClick(View view) {
switch(view.getId()){
case R.id.sub:
sub();
break;
case R.id.add:
add();
break;
}
}
public void onClick(View view) {
switch(view.getId()){
case R.id.sub:
sub();
break;
case R.id.add:
add();
break;
}
}
private void add() {
String s = count.getText().toString();
double v = Double.parseDouble(s);
v++;
count.setText(v+"");
}
String s = count.getText().toString();
double v = Double.parseDouble(s);
v++;
count.setText(v+"");
}
private void sub() {
String s = count.getText().toString();
double v = Double.parseDouble(s);
if(v>=1){
v--;
count.setText(v+"");
}
}
public String getCount(){
return count.getText().toString();
}
public void setCount(double count1){
count.setText(count1+"");
}
String s = count.getText().toString();
double v = Double.parseDouble(s);
if(v>=1){
v--;
count.setText(v+"");
}
}
public String getCount(){
return count.getText().toString();
}
public void setCount(double count1){
count.setText(count1+"");
}