Reputation: 93
I am using following code to pick date, however i wanted to pick the date as well as time (in a single dialog box)...
DatePickerDialog.OnDateSetListener beginDate = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
c.set(Calendar.YEAR,year);
c.set(Calendar.MONTH,monthOfYear);
c.set(Calendar.DAY_OF_MONTH,dayOfMonth);
setBeginDateOnView();
}
};
public void beginDateOnClick(View view) {
new DatePickerDialog(CreateEventActivity.this,beginDate,c.get(Calendar.YEAR),c.get(Calendar.MONTH),c.get(Calendar.DAY_OF_MONTH)).show();
}
public void setBeginDateOnView() {
String dateFormat = "dd-MM-yyyy";
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat, Locale.getDefault());
edtBeginDate.setText(sdf.format(c.getTime()));
Upvotes: 1
Views: 623
Reputation: 7918
There is no built-in "date and time picker in one" solution for Android, so you'll have to combine a DatePicker and a TimePicker into a dialog by yourself, or use a library that does it.
For a library, i can suggest using SlideDateTimePicker, i used it in a project a while back and it works well.
Or you can write your own, by simply creating a new class that extends AlertDialog, setting up 2 tabs inside it and then setting the tabs to include a DatePicker and a TimePicker.
Upvotes: 1