我的问题是,我的偏好活动从
AppCompatPreferenceActivity
我需要展示一个
DialogFragment
DialogFragmente dialogFragment= new MyDialogFragmentClass()
DialogFragment.show(getSupportFragmentManager(),"My Dialog")
由于无法使用
getSupportFragmentManager()
方法所以我的问题是,如果我的类从AppCompatipPreferenceActivity扩展而来,我该如何使用该方法。
我试过使用
getFragmentManager()
相反,但它也不起作用。
这是我的课程:
public class Settings_acticity extends AppCompatPreferenceActivity {
private SwitchPreference banner_switch;
private SharedPreferences sharedPreferences;
private ListPreference interstial_ad;
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
DialogFragment dialogFragment = new MyDialog();
dialogFragment.show(getSupportFragmentManager(), "My dialog");
}
}
和DialogFragment类:
public class MyDialog extends DialogFragment {
public MyDialog(){
// Required empty public constructor
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
View vista=getActivity().getLayoutInflater().inflate(R.layout.fragment_MyDialog,null);
setCancelable(false);
builder.setView(vista).setPositiveButton(R.string.aceptar, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
//Yes Code
}
}).setNegativeButton(R.string.cancelar, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
//No code
}
});
return builder.create();
}
}
谢谢你的帮助!