我有一个带有2个号码选择器的对话框(pickerMin& pickerSec)。我想使用这些数字来制作文本并在计算中使用它们。 但是,它目前没有返回任何内容。我已经尝试了多种方法从拾取器中获取数字并打印出来。我甚至试图将它设置为TextView。
我所需要的只是:
NumberPicker
提供一个号码,可以在Dialog
之外和项目的其他部分使用。klaar
按钮时执行此操作(此后对话框消失)。为了从NumberPicker获得结果,我到底做错了什么并且必须完成?
代码的破碎部分:
public void show(){
final Dialog timerDialog = new Dialog(MainActivity.this);
timerDialog.setTitle("Speeltijd helft");
timerDialog.setContentView(R.layout.timerdialog);
timerDialog.getWindow().setLayout(500, 600);
klaar = (Button) timerDialog.findViewById(R.id.btnSetTimer);
cancel = (Button) timerDialog.findViewById(R.id.btnCancelDialog);
pickerMin = (NumberPicker) timerDialog.findViewById(R.id.pickerMin);
pickerSec = (NumberPicker) timerDialog.findViewById(R.id.pickerSec);
pickerMin.setMaxValue(45);
pickerMin.setMinValue(0);
pickerSec.setMaxValue(45);
pickerSec.setMinValue(0);
pickerMin.setWrapSelectorWheel(true);
pickerSec.setWrapSelectorWheel(true);
klaar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
pickerMin.setOnValueChangedListener(new NumberPicker.OnValueChangeListener(){
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal){
minuten = picker.getValue();
out.println("pickerMin geeft: "+ minuten);
}
});
pickerSec.setOnValueChangedListener(new NumberPicker.OnValueChangeListener(){
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal){
seconden = picker.getValue();
out.println("pickerSec geeft: "+ seconden);
}
});
Timerklok.setText(String.format("%02d", minuten)+":"+String.format("%02d",seconden)); //set the value to TextView
timerDialog.dismiss();
}
});
cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
timerDialog.dismiss(); //dismiss dialog
}
});
timerDialog.show();
}