2017-07-08 5 views
0

// J'ai besoin d'extraire newVal de toutes ces méthodes numberpickers séparément, et je les mets en textviews, mais quand j'essaie d'obtenir de la valeur depuis l'application d'affichage de texte crash.can tu m'aides . Comment puis-je obtenir la valeur numberpicker en dehors de sa méthode onValuechange?Récupère la valeur de numberpicker et la place dans un textview

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); 


     } 

    }); 


} 

}

Répondre

0

textview6 est un objet nul. Il n'a pas d'instance de TextView.

+0

donc désolé par le mauvais. J'ai codé dans mon code mais ne fonctionne toujours pas! –

+0

mettre à jour votre code s'il vous plaît – Jay

+0

désolé je viens de le faire! –