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()));
現在の時刻に従って数値ピッカーの値を動的に設定しますが、次の方法でコードを記述し、数値形式の例外を取得しています。
現在の時刻に従って、午前午後の値を番号ピッカーに設定したいのですが、それを達成する方法を教えてください。よろしくお願いします..