Created
June 15, 2012 08:21
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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