Android開発にTimePickerで実装サンプルコード
サンプルコード:
// 現在の時刻を取得
Calendar calendar = Calendar.getInstance();
calendar.setTimeZone(TimeZone.getTimeZone(“GMT+8"));
if (mHour == -1 && mMinute == -1) {
mHour = calendar.get(Calendar.HOUR_OF_DAY);
mMinute = calendar.get(Calendar.MINUTE);
}
mTimePicker = (TimePicker) findViewById(R.id.timePicker);
mTimePicker.setCurrentHour(mHour);
mTimePicker.setCurrentMinute(mMinute);
mTimePicker
.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() {
@Override
public void onTimeChanged(TimePicker view, int hourOfDay,
int minute) {
mHour = hourOfDay;
mMinute = minute;
}
});