Custom addition/subtraction controls and custom digital controls
1 _ requirements for custom addition and subtraction controls
Create Module-NumberAddSubView
A _ only numbers can be entered and cannot be entered through the keyboard
B _ use the plus or minus button to operate a number
C _ listener addition and subtraction buttons
The D _ array has the limit of minimum and maximum values.
E _ Custom Attributes
2. provides an interface for the outside world to listen for changes in numbers.
1 _ setting Interface
@ Overridepublic void onClick (View v) {if (v. getId () = R. id. btn_sub) {// Toast. makeText (mContext, "minus", Toast. LENGTH_SHORT ). show (); subNum (); if (onButtonClickListenter! = Null) {onButtonClickListenter. onButtonSubClick (v, value) ;}} else if (v. getId () = R. id. btn_add) {// Toast. makeText (mContext, "plus", Toast. LENGTH_SHORT ). show (); addNum (); if (onButtonClickListenter! = Null) {onButtonClickListenter. onButtonAddClick (v, value );}}} public interface OnButtonClickListenter {/*** call back this method when the Add button is clicked ** @ param view * @ param value */public void onButtonAddClick (View view, int value ); /*** call back this method when the reduce button is clicked ** @ param view * @ param value */public void onButtonSubClick (View view, int value );} private OnButtonClickListenter onButtonClickListenter; public void setOnButtonClickListenter (OnButtonClickListenter onButtonClickListenter) {this. onButtonClickListenter = onButtonClickListenter ;}
2 _ listener changes
public class MainActivity extends AppCompatActivity { private NumberAddSubView nb_addsub_view; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); nb_addsub_view = (NumberAddSubView) findViewById(R.id.nb_addsub_view); nb_addsub_view.setOnButtonClickListenter(new NumberAddSubView.OnButtonClickListenter() { @Override public void onButtonAddClick(View view, int value) { Toast.makeText(MainActivity.this,"AddClick Vaule=="+value,Toast.LENGTH_SHORT).show(); } @Override public void onButtonSubClick(View view, int value) { Toast.makeText(MainActivity.this,"SubClick Vaule=="+value,Toast.LENGTH_SHORT).show(); } }); }}
Github complete code: https://github.com/ganchuanpu/NumberAddSubView