title: Showing TimePicker dialog from PreferenceFragment activity
body: <p>Hi!</p>
  
  <p>I want to my application to show a TimePicker dialog when the user clicks on a settings item (Preference). I've already created a DialogFragment that creates a TimePicker dialog, but i'm unable to tie this fragment with a Custom Preference. How could this be done?</p>
  
  <p>Here's the DialogFragment class that needs to be tied together with the Custom Preference:</p>
  
  <pre><code>import java.util.Calendar;
  import android.app.Dialog;
  import android.app.TimePickerDialog;
  import android.os.Bundle;
  import android.app.DialogFragment;
  import android.text.format.DateFormat;
  import android.widget.TimePicker;
  
  public class MyDialogFragment extends DialogFragment implements TimePickerDialog.OnTimeSetListener {
  
      @Override
      public Dialog onCreateDialog(Bundle savedInstanceState) {
          // Use the current time as the default values for the picker
          final Calendar c = Calendar.getInstance();
          int hour = c.get(Calendar.HOUR_OF_DAY);
          int minute = c.get(Calendar.MINUTE);
  
          // Create a new instance of TimePickerDialog and return it
          return new TimePickerDialog(getActivity(), this, hour, minute,
                  DateFormat.is24HourFormat(getActivity()));
      }
  
      public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
          // Do something with the time chosen by the user
          Calendar calendar = Calendar.getInstance();
          calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
          calendar.set(Calendar.MINUTE, minute);
          calendar.set(Calendar.SECOND, 0);
          ((OpeningScreen) getActivity()).timerAlert(calendar.getTimeInMillis());
  
      }
  }
  </code></pre>
  
  <p></p>PS. I've read the android developer's tutorial (<a href="http://developer.android.com/guide/topics/ui/settings.html" rel="nofollow">http://developer.android.com/guide/topics/ui/settings.html</a>), but that's a bit too confusing for me. Thank you very much for your help!</p></p>