public
Last active

A simple fragment for displaying a date picker on Android. For use with the new Fragments API

  • Download Gist
DatePickerDialogFragment.java
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
import java.util.Calendar;
 
import android.app.DatePickerDialog;
import android.app.DatePickerDialog.OnDateSetListener;
import android.app.Dialog;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
 
public class DatePickerDialogFragment extends DialogFragment {
 
private OnDateSetListener mDateSetListener;
 
public DatePickerDialogFragment() {
// nothing to see here, move along
}
 
public DatePickerDialogFragment(OnDateSetListener callback) {
mDateSetListener = (OnDateSetListener) callback;
}
 
public Dialog onCreateDialog(Bundle savedInstanceState) {
Calendar cal = Calendar.getInstance();
 
return new DatePickerDialog(getActivity(),
mDateSetListener, cal.get(Calendar.YEAR),
cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH));
}
 
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.