从numberpicker获取价值并将其放入textview

时间:2017-07-08 05:09:10

标签: android textview android-number-picker

//我需要分别从所有这些numberpickers方法中获取newVal,然后我将它们设置为textviews,但是当尝试从文本视图应用程序中获取值时,你可以帮助我。我怎样才能获得numberpicker值以外的onValuechange方法?

  public class MainActivity extends AppCompatActivity {




ImageButton start,pause,reset;
TextView total,mintimer,sectimer,textView6,textView7,textView8;



@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    start=(ImageButton)findViewById(R.id.start);
    pause=(ImageButton)findViewById(R.id.pause);
    reset=(ImageButton)findViewById(R.id.reset);

    total=(TextView)findViewById(R.id.total);
    mintimer=(TextView)findViewById(R.id.mintimer);
    sectimer=(TextView)findViewById(R.id.sectimer);

     //this is how i tried to get textview value as a string. then the app 
     crashes
    String a=textView6.getText().toString();

    NumberPicker min = (NumberPicker) findViewById(R.id.min);
    NumberPicker sec = (NumberPicker) findViewById(R.id.sec);
    NumberPicker brk = (NumberPicker) findViewById(R.id.brk);


    min.setMinValue(1);
    min.setMaxValue(20);
    min.setWrapSelectorWheel(true);
    min.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
        @Override
        public void onValueChange(NumberPicker picker, int oldVal, int newVal) {         
           textView6=(TextView)findViewById(R.id.textView6);
           textView6.setText(" "+newVal);

        }
    });

    //beep sound breake
    sec.setMaxValue(60);
    sec.setMinValue(0);
    sec.setWrapSelectorWheel(true);
    sec.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {

        @Override
        public void onValueChange(NumberPicker picker, int oldVa2, int newVal2) {
            textView7=(TextView)findViewById(R.id.textView7);
            textView7.setText(" "+newVal2);
        }
    });
    //Break

    brk.setMaxValue(5);
    brk.setMaxValue(60);
    brk.setWrapSelectorWheel(true);
    brk.setOnValueChangedListener(new NumberPicker.OnValueChangeListener(){
        @Override
        public void onValueChange(NumberPicker picker ,int oldVal3,int newVal3){
            textView8=(TextView)findViewById(R.id.textView8);

            textView8.setText(" "+newVal3);


        }

    });


}

}

1 个答案:

答案 0 :(得分:0)

textview6是一个空对象。它没有TextView实例。