【发布时间】:2017-11-08 11:20:36
【问题描述】:
我正在开发用于显示 AM 和 PM 值的自定义数字选择器。请检查下面的数字选择器代码。
<com.naushad.kenocustomer.util.NumberPicker
android:id="@+id/np_ampm"
android:layout_width="wrap_content"
android:layout_height="130dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_centerHorizontal="true"/>
XML 代码如下所示,下面是 java 代码。
final String ampm[] = {"AM", "PM"};
datetimeBinding.npAmpm.setFormatter(R.string.number_picker_formatter);
datetimeBinding.npAmpm.setSelectedTextColor(Color.parseColor("#09bcf2"));
datetimeBinding.npAmpm.setTextColor(Color.parseColor("#babdc2"));
datetimeBinding.npAmpm.setDefaultSelectedTextSize(20);
datetimeBinding.npAmpm.setTextSize(getResources().getDimension(R.dimen.fifteen));
datetimeBinding.npAmpm.setMinValue(1);
datetimeBinding.npAmpm.setMaxValue(ampm.length);
datetimeBinding.npAmpm.setDisplayedValues(ampm);
int isAM = c.get(Calendar.AM_PM);
int myValue = Arrays.asList(ampm).indexOf(String.valueOf(isAM));
if(isAM == 0)
datetimeBinding.npAmpm.setValue(Integer.parseInt(ampm[1].toString()));
else
datetimeBinding.npAmpm.setValue(Integer.parseInt(ampm[1].toString()));
现在我将根据当前时间动态设置数字选择器值。但我已经按照以下方式编写代码并获得 数字格式异常。
我想根据当前时间将 am pm 值设置为数字选择器。请建议我如何实现这一点。提前谢谢..
【问题讨论】:
标签: android numberpicker android-number-picker