0

I'm implementing a Fragment that calls two TimePickerDialog's as answered here.

But that answer implements it in a activity and then uses a instance of the listener using

mListener = getActivity() instanceof TimePickerDialogListener ? (TimePickerDialogListener) getActivity() : null;

How can I get the Listener instance in my Fragment that implements the TimePickerDialogListener?

Community
  • 1
  • 1
Tgo1014
  • 536
  • 1
  • 7
  • 17

1 Answers1

2

To create a time picker

If you simply want to use a time picker you can use TimePickerDialog and provide it with a TimePickerDialogListener

public void showTimePicker(int hour,int minute,boolean is24HourViews) {
        TimePickerDialog timePickerDialog = new TimePickerDialog(getActivity(),
                new TimePickerDialog.OnTimeSetListener() {
                    @Override
                    public void onTimeSet(TimePicker timePicker, int hour, int minute) {
                        //Do your setup
                    }
                }, hour, minute,is24HourView);
        timePickerDialog.show(); //Show the dialog
}
Rohan Arora
  • 661
  • 5
  • 15
  • THANKS! I've spend my entire afternoon trying to make this work with interfaces, another class and many others random things. You made it with one method! Thanks you so much! – Tgo1014 Aug 05 '16 at 00:49