I have implemented directory picker as a DialogFragment
and now I would like to use it in DialogPreference
. Is it possible? How to do it?
Is it possible to build DialogPreference from DialogFragment?
Asked Answered
It's not obvious to me what exactly you want to do, but I'm assuming you have a Fragment layout which you want to show on a Preference click. Here is the code for it:
preferences.xml
<PreferenceScreen ... >
...
<Preference android:title="Dialog Fragment Displayer"
android:key="dialog_preference"
android:selectable="true"/>
...
</PreferenceScreen>
PreferenceActivity.java (or wherever your main settings control is)
final Activity activity = getActivity(); //replace with this if in an Activity
Preference p = findPreference("dialog_preference");
p.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean OnPreferenceClick(Preference preference) {
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
View view = activity.getLayoutInflater().inflate(R.layout.your_fragment, null, false);
builder.setView(view);
builder.create().show();
}
});
© 2022 - 2024 — McMap. All rights reserved.