I am using material Date
Time
picker for my Android app. But I want to combine the Date
and Time
picker in one dialog.
You Can Get Date
And Time
One By One Using Pickers
In Android.
Calendar getDate = Calendar.getInstance();
cDay = getDate.get(Calendar.DAY_OF_MONTH);
cMonth = getDate.get(Calendar.MONTH);
cYear = getDate.get(Calendar.YEAR);
timePickerDialog = new TimePickerDialog(DesignActivity.this, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
final String AM_PM ;
if (hourOfDay > 12) {
hourOfDay -= 12;
AM_PM = "pm";
} else if (hourOfDay == 0) {
hourOfDay += 12;
AM_PM = "am";
} else if (hourOfDay == 12)
AM_PM = "pm";
else
AM_PM = "am";
hour1 = hourOfDay;
minutes1 = minute;
DatePickerDialog datePicker = new DatePickerDialog(DesignActivity.this, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
cYear = year;
cMonth = month;
cDay = dayOfMonth;
editText.setText(hour1 + ":" +minutes1 + AM_PM + " " + cDay + "/" + cMonth + "/" + cYear);
}
},cYear,cMonth,cDay);
datePicker.show();
}
},hour1,minutes1,false);
timePickerDialog.show();
}
});
If You Will Need More Explanation About Click This.