我已将目录选择器实现为DialogFragment
,现在我想在DialogPreference
中使用它。可能吗?怎么做?
答案 0 :(得分:0)
对我来说,确切要执行的操作并不明显,但是我假设您要在“偏好设置”点击中显示“片段”布局。这是它的代码:
preferences.xml
<PreferenceScreen ... >
...
<Preference android:title="Dialog Fragment Displayer"
android:key="dialog_preference"
android:selectable="true"/>
...
</PreferenceScreen>
PreferenceActivity.java (或您的主要设置控件位于何处)
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();
}
});