Main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TimePicker android:id="@+id/time1" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <DatePicker android:id="@+id/date1" android:layout_width="fill_parent" android:layout_height="wrap_content"/> </LinearLayout>
类
package com.android.Main; import android.app.Activity; import android.os.Bundle; import android.widget.DatePicker; import android.widget.TimePicker; public class ActivityMain extends Activity { private TimePicker time1; private DatePicker date1; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); time1=(TimePicker)this.findViewById(R.id.time1); date1=(DatePicker)this.findViewById(R.id.date1); time1.setIs24HourView(true); time1.setCurrentHour(18); time1.setCurrentMinute(25); date1.updateDate(2005,6, 27); } }