Skip to content

Instantly share code, notes, and snippets.

@ishitcno1
Last active December 20, 2015 09:40
Show Gist options
  • Save ishitcno1/6109868 to your computer and use it in GitHub Desktop.
Save ishitcno1/6109868 to your computer and use it in GitHub Desktop.
android date picker fragment
private class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH);
int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
return new DatePickerDialog(getActivity(), this, year, month, dayOfMonth);
}
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, monthOfYear);
calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
//do some stuff
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment