Skip to content

Instantly share code, notes, and snippets.

@codinguser
Created June 15, 2012 08:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save codinguser/2935353 to your computer and use it in GitHub Desktop.
Save codinguser/2935353 to your computer and use it in GitHub Desktop.
A simple fragment for displaying a date picker on Android. For use with the new Fragments API
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));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment