How to call a DialogFragment on Preference click event?

600 views Asked by At

I am making an Alarm app on android. I am newbie in Android. I want to call the Time Picker dialog fragment when one of the Preferences is clicked. I already have created a class which creates the dialog. The code which i am using to call the dialog box is:

TimePickerFragment newFragment=new TimePickerFragment();
newFragment.show(getFragmentManager(), "dialog");`

The above code works for button click event but not for preference click.

1

There are 1 answers

0
Nitish Srivastava On

If you have made the Preference Activity then try it once

just Override -

@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {

    String key = preference.getKey();
    //check the key and open dialog

    return super.onPreferenceTreeClick(preferenceScreen, preference);
}