晕,如何使 timePickerDialog 显示在带有 AM 和 PM 的 EditText 上?设置 timePickerDialog 后,有 24 小时格式。例如,晚上 7.45,EditText 将得到 19.45,仅此而已。我希望它是 EditText 中的 7.45 pm。有人可以帮忙吗?
这是我的编码...
private TimePickerDialog.OnTimeSetListener timePickerListener = new TimePickerDialog.OnTimeSetListener() {
public void onTimeSet(TimePicker view, int selectedHour,
int selectedMinute) {
hour = selectedHour;
minute = selectedMinute;
String zone = "";
if (Calendar.AM_PM == Calendar.AM)
zone = "AM";
else if (Calendar.AM_PM == Calendar.PM)
zone = "PM";
// set current time into textview
timeField.setText(new StringBuilder().append(pad(hour)).append(":").append(pad(minute)).append(" ").append(zone));
}
};
private static String pad(int c) {
if (c >= 10)
return String.valueOf(c);
else
return "0" + String.valueOf(c);
}