Custom number plus minus controls

Source: Internet
Author: User

1_ requirements for custom digital plus and minus controls

Create Module-numberaddsubview

A_ input can only be a number, and cannot be entered by the keyboard

B_ manipulating numbers with the Add and subtract buttons

C_ Monitor plus minus button

D_ array with minimum and maximum limits

E_ Custom Properties

2. Provide an interface to allow external monitoring to hear the changes in numbers

1_ Setting the 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 {/** * When the Add button is clicked, callback the method * * @param view * @param value */public void ONBUTTONADDCL  Ick (view view, int value);/** * When the decrease button is clicked, the callback method * * @param view * @param value */public void Onbuttonsubclick (view view, int value);} Private Onbuttonclicklistenter onbuttonclicklistenter;public void Setonbuttonclicklistenter (OnButtonClickListenter Onbuttonclicklistenter) {this.onbuttonclicklistenter = Onbuttonclicklistenter;}

2_ Monitoring 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 Full code: Https://github.com/ganchuanpu/NumberAddSubView

Custom number plus minus controls

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.