Tgo1014 Tgo1014 - 1 year ago 112
Android Question

Get instance of a Listener in a Fragment

I'm implementing a Fragment that calls two

'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

Answer Source

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() {
                    public void onTimeSet(TimePicker timePicker, int hour, int minute) {
                        //Do your setup
                }, hour, minute,is24HourView);; //Show the dialog
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download