Android DatePicker, TimePicker控件的使用
public class TimerPickerActivity extends Activity{ private DatePicker datePicker; private TimePicker timePicker; private static Calendar calendar = Calendar.getInstance(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.timepicker); timePicker = (TimePicker)findViewById(R.id.timePicker1); datePicker = (DatePicker)findViewById(R.id.datePicker1); timePicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() { @Override public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { // TODO Auto-generated method stub StringBuffer buffer = new StringBuffer(); buffer.append(hourOfDay < 10 ? "0" + hourOfDay:hourOfDay ); buffer.append(":").append(minute); Toast.makeText(TimerPickerActivity.this, buffer.toString(), Toast.LENGTH_SHORT).show(); } }); datePicker = (DatePicker)findViewById(R.id.datePicker1); int year = calendar.get(Calendar.YEAR); int month = calendar.get(Calendar.MONTH); int day = calendar.get(Calendar.DAY_OF_MONTH); datePicker.init(year, month, day, new DatePicker.OnDateChangedListener() { @Override public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) { // TODO Auto-generated method stub } }); } }