我在我的設置屏幕中有一個時間選擇器對話框。當用戶點擊時間選擇器對話時,用戶選擇時間。但是當用戶再次點擊時間選擇器時,時間選擇器對話將顯示當前時間而不是所選時間。 這是我到目前爲止所做的。設置時間選擇器對話到選定時間
mreminder.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Calendar mcurrentTime = Calendar.getInstance();
final int[] hour = {mcurrentTime.get(Calendar.HOUR_OF_DAY)};
int minute = mcurrentTime.get(Calendar.MINUTE);
TimePickerDialog mTimePicker;
mTimePicker = new TimePickerDialog(SettingsActivity.this, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinute) {
int hour = selectedHour;
int minutes = selectedMinute;
String timeSet = " ";
if (hour > 12) {
hour -= 12;
timeSet = "PM";
} else if (hour == 0) {
hour += 12;
timeSet = "AM";
} else if (hour == 12)
timeSet = "PM";
else
timeSet = "AM";
String min = "";
if (minutes < 10)
min = "0" + minutes;
else
min = String.valueOf(minutes);
// Append in a StringBuilder
String aTime = new StringBuilder().append(hour).append(':')
.append(min).append(" ").append(timeSet).toString();
mreminder.setText(aTime);
pref.savePref(REMINDER, aTime);
}
}, hour[0], minute, false);
mTimePicker.setTitle("Select Time");
mTimePicker.show();
}
});
有人能告訴我如何在下次用戶點擊它時將timepicker設置爲所選時間。
[Android:在文本視圖中顯示時間設置時間選擇器]可能的重複(http://stackoverflow.com/questions/12494074/android-setting-time-in-time-picker-with-the顯示在文本視圖中) –
[如何在TimePicker中設置自定義時間]的可能重複(http://stackoverflow.com/questions/31376072/how-to-set-custom-time-in-timepicker ) –
我不能得到它,你可以告訴我關於我的代碼。 –