MyView类
public class MyView extends LinearLayout {
private ImageView iv_add;
private ImageView iv_del;
private TextView tv_num;
public MyView(Context context) {
this(context, null);
}
public MyView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
View view = LayoutInflater.from(context).inflate(R.layout.myview, this);
iv_add = findViewById(R.id.iv_add);
iv_del = findViewById(R.id.iv_del);
tv_num = findViewById(R.id.tv_num);
}
public void setAddClickListener(OnClickListener onClickListener) {
iv_add.setOnClickListener(onClickListener);
}
public void setDelClickListener(OnClickListener onClickListener) {
iv_del.setOnClickListener(onClickListener);
}
public void setNum(String num) {
tv_num.setText(num);
}
public int getNum() {
String num = tv_num.getText().toString();
return Integer.parseInt(num);
}
}