當numberpicker被加載時,默認值沒有出現在屏幕上直到被觸摸。Android Numberpicker的默認值沒有出現
一旦感動,一切正常。任何幫助表示讚賞。
此外,如果格式化程序被刪除,它工作正常。
dialog.xml
<NumberPicker
android:id="@+id/number_picker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/apply_button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/number_picker"
android:text="@string/ok_string" />
這裏是活動的代碼:
final NumberPicker np = (NumberPicker) d.findViewById(R.id.number_picker);
np.setMaxValue(50);
np.setMinValue(0);
np.setWrapSelectorWheel(true);
np.setOnValueChangedListener(this);
np.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
np.setFormatter(new NumberPicker.Formatter() {
@Override
public String format(int i) {
if (i == 25)
return "0";
else
return String.valueOf(i - 25);
}
});
np.setValue(25);
在此先感謝
難道是初始文本顏色與背景顏色相匹配嗎?很難想象沒有設備時你所看到的內容。 – stkent 2014-12-07 14:51:33
[格式化的Android NumberPicker可能重複不會在第一次呈現時格式化](https://stackoverflow.com/questions/17708325/android-numberpicker-with-formatter-does-not-format-on-first-rendering) – 2017-07-14 09:31:41