例如,当我在 18:00 创建这个 timePicker(below) 时,timePicker 的 timeValue 将为 06:00。在 19:44->07:44... 因此,从 AM/PM 切换到 24 小时模式后,它不会移动到正确的当前时间。我该如何改变呢?我的目标是 timePicker 显示创建它的当前时间。就像我在 AM/PM 模式下使用它时一样。
TimePicker timePicker = (TimePicker) convertView.findViewById(R.id.time_picker);
timePicker.setIs24HourView(true);
对不起,糟糕的表述,希望你能理解我的问题。否则就问吧。
更新:
public class ChooseTimeViewDialog extends AlertDialog {
protected Context context;
public ChooseTimeViewDialog(final Context context) {
super(context);
this.context = context;
}
public void onCreate(Bundle savedInstanceState) {
LayoutInflater inflater = this.getLayoutInflater();
View convertView = inflater.inflate(R.layout.dialog_choose_time_view, null);
setContentView(convertView);
setTitle(R.string.title_dialog_choose_time_view);
final TimePicker taskTimePicker = (TimePicker) convertView.findViewById(R.id.dctv_task_time_picker);
taskTimePicker.setIs24HourView(true);
setButton(DialogInterface.BUTTON_POSITIVE, "Choose", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
int hour = taskTimePicker.getCurrentHour();
int minute = taskTimePicker.getCurrentMinute();
Calendar cal = new GregorianCalendar();
cal.set(0, 0, 0, hour, minute, 0);
((AddTaskViewActivity) context).setSelectedTime(cal.getTime());
}
});
setButton(DialogInterface.BUTTON_NEUTRAL, "No time", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
((AddTaskViewActivity) context).setSelectedTime(null);
}
});
}
}
XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TimePicker
android:id="@+id/dctv_task_time_picker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
在我将初始化移动到 onCreate 并使用 setContentView(View) 后,对话框的背景是透明的,它是全屏的并且没有按钮..为什么?