我有一个24小时格式的时间选择器。现在我想以24小时格式显示当前设备时间,无论设备时间格式如何。现在我的设备是12小时格式,所以例如我的时间是下午2点04分,时间选择器应该是14点04分。基于设备时间在timepicker中设置默认时间
这是我的代码或timepicker。它在不同的布局上,因为我在对话框中显示它们。
XML:
<LinearLayout android:id="@+id/datetimepickerLayout" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="10dp" xmlns:android="http://schemas.android.com/apk/res/android">
<DatePicker android:id="@+id/datePicker1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center"></DatePicker>
<TimePicker android:id="@+id/timePicker1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center"></TimePicker>
<Button
android:id="@+id/setdatetimeBtn1"
android:text="Set"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_gravity="center"/>
现在在我的Java代码:
timePicker1 = (TimePicker)dialog.findViewById(R.id.timePicker1);
datePicker1 = (DatePicker)dialog.findViewById(R.id.datePicker1);
setDateTimeBtn1 = (Button)dialog.findViewById(R.id.setdatetimeBtn1);
datePicker1.setCalendarViewShown(false);
timePicker1.setIs24HourView(true);
任何想法?谢谢!
看到http://stackoverflow.com/questions/12494074/android-setting-time-in-time-picker-with-the-time-shown-in-text-view –
看到这个链接http:// www .mkyong.com/android/android-date-picker-example/ –
伟大的链接@Shayanpourvatan。谢谢! – ljpv14