Code example for DialogFragment

Methods: getFragmentManager

import android.text.format.DateFormat; 
import android.view.View; 
import android.widget.TimePicker; 
public class TimePickerFragment extends DialogFragment implements TimePickerDialog.OnTimeSetListener {
	private TimePickedListener mListener;
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		final Calendar c = Calendar.getInstance();
		int hour = c.get(Calendar.HOUR_OF_DAY);
		int minute = c.get(Calendar.MINUTE);
		return new TimePickerDialog(getActivity(), this, hour,minute,DateFormat.is24HourFormat(getActivity()));
	public interface TimePickedListener { 
		public void onTimePicked(int hour, int minute);
	public void onAttach(Activity activity) {
		// This makes sure that the container activity has implemented 
		// the callback interface. If not, it throws an exception 
		try { 
			mListener = (TimePickedListener) activity;
		} catch (ClassCastException e) {
			throw new ClassCastException(activity.toString()
					+ " must implement OnTimeSetListener"); 
	public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
		mListener.onTimePicked(hourOfDay, minute);
	public void showTimePickerDialog(View view) {
		DialogFragment newFragment = new TimePickerFragment ();, "timePicker");