0
我發現號碼選取器存在一些問題。Android號碼選取器
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
// Get the layout inflater
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.dialog, null);
final NumberPicker np = (NumberPicker) view.findViewById(R.id.numberPicker1);
builder.setView(view)
// Add action buttons
.setPositiveButton(R.string.done, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
// sign in the user ...
seekBar.setProgress(np.getValue());
dialog.dismiss();
}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
builder.setTitle("Pick value");
np.setMinValue(0);
np.setMaxValue(max - min);
int value_now;
switch (notification.dataType) {
case 0:
value_now = Math.round(UnitConverter.getTemperatureValue(notification.value));
break;
case 1:
value_now = (int) notification.value;
break;
case 2:
value_now = Math.round(UnitConverter.getPressureValue(notification.value));
break;
case 3:
value_now = Math.round(UnitConverter.getRainfallValue(notification.value));
break;
case 4:
default:
value_now = Math.round(UnitConverter.getWindSpeedValue(notification.value));
break;
}
np.setValue(value_now - min);
np.setFormatter(new NumberPicker.Formatter() {
@Override
public String format(int index) {
return Integer.toString(index + min);
}
});
np.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
np.setWrapSelectorWheel(false);
AlertDialog dialog = builder.create();
dialog.show();
問題是,當有時value_now大於100時,當前值不會顯示。但是,如果我滾動數字選擇器,它將再次顯示。