Date value = new Date();
final Calendar cal = Calendar.getInstance();
cal.setTime(value);
new DatePickerDialog(this,
new DatePickerDialog.OnDateSetListener() {
@Override public void onDateSet(DatePicker view,
int y, int m, int d) {
cal.set(Calendar.YEAR, y);
cal.set(Calendar.MONTH, m);
cal.set(Calendar.DAY_OF_MONTH, d);
// now show the time picker
new TimePickerDialog(NoteEditor.this,
new TimePickerDialog.OnTimeSetListener() {
@Override public void onTimeSet(TimePicker view,
int h, int min) {
cal.set(Calendar.HOUR_OF_DAY, h);
cal.set(Calendar.MINUTE, min);
value = cal.getTime();
}
}, cal.get(Calendar.HOUR_OF_DAY),
cal.get(Calendar.MINUTE), true).show();
}
}, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH),
cal.get(Calendar.DAY_OF_MONTH)).show();
private SlideDateTimeListener listener = new SlideDateTimeListener() {
@Override
public void onDateTimeSet(Date date)
{
// Do something with the date. This Date object contains
// the date and time that the user has selected.
}
@Override
public void onDateTimeCancel()
{
// Overriding onDateTimeCancel() is optional.
}
};
然后创建并显示对话框:
new SlideDateTimePicker.Builder(getSupportFragmentManager())
.setListener(listener)
.setInitialDate(new Date())
.build()
.show();
Then onDateSet callback store date & show TimePicker
@Override
public void onDateSet(DatePickerDialog view, int year, int monthOfYear, int dayOfMonth) {
Calendar cal = Calendar.getInstance();
cal.set(year, monthOfYear, dayOfMonth);
filter.setDate(cal.getTime());
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
showTimePicker();
}
},500);
}
On onTimeSet callback store time
@Override
public void onTimeSet(RadialPickerLayout view, int hourOfDay, int minute) {
Calendar cal = Calendar.getInstance();
if(filter.getDate()!=null)
cal.setTime(filter.getDate());
cal.set(Calendar.HOUR_OF_DAY,hourOfDay);
cal.set(Calendar.MINUTE,minute);
}
Calendar date;
public void showDateTimePicker() {
final Calendar currentDate = Calendar.getInstance();
date = Calendar.getInstance();
new DatePickerDialog(context, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
date.set(year, monthOfYear, dayOfMonth);
new TimePickerDialog(context, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
date.set(Calendar.HOUR_OF_DAY, hourOfDay);
date.set(Calendar.MINUTE, minute);
Log.v(TAG, "The choosen one " + date.getTime());
}
}, currentDate.get(Calendar.HOUR_OF_DAY), currentDate.get(Calendar.MINUTE), false).show();
}
}, currentDate.get(Calendar.YEAR), currentDate.get(Calendar.MONTH), currentDate.get(Calendar.DATE)).show();
}