简体   繁体   中英

How to call a DialogFragment on Preference click event?

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.

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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM