Custom addition/subtraction controls and custom digital controls

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.