I have 2 numberPicker
in one dialog
. The problem is that if I select "seconds" and then "minutes" and click ok, the numbers are saved well . But if I do it the other way around, the seconds take those of the previous configuration, why?
I have put it, as there is only 1 button, which is saved in the 1st numberpicker
, inuser_minutos.setText
//PRIMER NUMBERPICKER
NumberPicker.OnValueChangeListener myValChangedListener = new NumberPicker.OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
user_minutos.setText(newVal + " min "+ minutos2 +"seg");
minutos = newVal;
}
};
aNumberPicker.setOnValueChangedListener(myValChangedListener);
//SEGUNDO NUMBERPICKER
NumberPicker.OnValueChangeListener myValChangedListener2 = new NumberPicker.OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal2) {
//user_minutos.setText(newVal + " seg");
minutos2 = newVal2;
}
};
aNumberPickerA.setOnValueChangedListener(myValChangedListener2);
Assuming that ''minutes2'' is set as a class variable, what happens is that when you give the first datapicker the value of ''newVal'' is updated and your info comes out correct, when you give the seconds it is update the information of seconds and when you give your data picker of minutes the seconds are updated. and it comes out correct again.
When you give seconds a second time, you update the seconds value in the variable but not in inputtext so it doesn't change.