Skip to content

Instantly share code, notes, and snippets.

@sharifulislam52
Created March 1, 2018 15:56
Show Gist options
  • Save sharifulislam52/adb312882fa48d35173f159a74a62d93 to your computer and use it in GitHub Desktop.
Save sharifulislam52/adb312882fa48d35173f159a74a62d93 to your computer and use it in GitHub Desktop.
static final int dialog_id = 0;
int year_x, month_x, day_x;
final Calendar cal = Calendar.getInstance();
year_x = cal.get(Calendar.YEAR);
month_x = cal.get(Calendar.MONTH);
day_x = cal.get(Calendar.DAY_OF_MONTH);
// call 'showDialog(dialog_id)' method for show data picker
@Override
protected Dialog onCreateDialog(int id){
if(id == dialog_id) {
return new DatePickerDialog(your_activity.this, kDate, year_x, month_x, day_x);
}
return null;
}
private DatePickerDialog.OnDateSetListener kDate = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker datePicker, int i, int i1, int i2) {
year_x = i;
month_x = i1 + 1; // month start from 0 that why we add 1
day_x = i2;
// what we want to do
}
};
// dialog_id, year_x, month_x, day_x, cal, kDate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment