2014-10-07 15 views
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時,當前值不會顯示。但是,如果我滾動數字選擇器,它將再次顯示。 enter image description here

回答

0

您是否在XML中設置最大值?

試試你的敏

np.setMinValue後設置它(0);

np.setMaxValue(6000);

OR

這使得您的代碼更長,但似乎是這樣做的最佳方式: Take a look HERE