得到这三个numberPickers的总和?

时间:2017-08-13 12:41:28

标签: android android-number-picker

我有三个buttonS.from每个按钮,我得到一个数字,我想得到这三个数字的总和,并在Textview显示总和。

enter image description here

NumberPicker np1,np2 ;

//Todo: this is for the BigButton
public void showBig()
{

    final Dialog d = new Dialog(HomeActivity.this);
    d.setTitle("NumberPicker");
    d.setContentView(R.layout.timer_dailog);
    Button b1 = (Button) d.findViewById(R.id.button1);
    Button b2 = (Button) d.findViewById(R.id.button2);
     np1 = (NumberPicker) d.findViewById(R.id.numberPicker1);
    np1.setMaxValue(100);
    np1.setMinValue(0);
    np1.setWrapSelectorWheel(false);
    np1.setOnValueChangedListener(this);
    b1.setOnClickListener(new OnClickListener()
    {
        @Override
        public void onClick(View v) {

            theSum.setText(String.valueOf(np1.getValue()+np2.getValue()));

            btn_NumBig.setText(""+np1.getValue());
            d.dismiss();
        }
    });
    b2.setOnClickListener(new OnClickListener()
    {
        @Override
        public void onClick(View v) {
            d.dismiss();
        }
    });
    d.show();


}




//Todo: this is for the smallButton
public void showSmall()
{

    final Dialog d = new Dialog(HomeActivity.this);
    d.setTitle("NumberPicker");
    d.setContentView(R.layout.timer_dailog);
    Button b1 = (Button) d.findViewById(R.id.button1);
    Button b2 = (Button) d.findViewById(R.id.button2);
     np2 = (NumberPicker) d.findViewById(R.id.numberPicker1);
    np2.setMaxValue(100);
    np2.setMinValue(0);
    np2.setWrapSelectorWheel(false);
    np2.setOnValueChangedListener(this);
    b1.setOnClickListener(new OnClickListener()
    {
        @Override
        public void onClick(View v) {

            theSum.setText(String.valueOf(np1.getValue()+np2.getValue()));
            btn_NumSmall.setText(""+np2.getValue());
            d.dismiss();
        }
    });
    b2.setOnClickListener(new OnClickListener()
    {
        @Override
        public void onClick(View v) {
            d.dismiss();
        }
    });
    d.show();


}

}

0 个答案:

没有答案