내 문제는 내 선호 활동이 AppCompatPreferenceActivity
에서 확장되어 있고 DialogFragment
을 보여줄 필요가 있다는 것입니다. 나는 다음 작업을 수행 할 때 그래서 : 나는 getSupportFragmentManager()
방법을 사용할 수 없기 때문에클래스의 DialogFragment가 AppCompatPreferenceActivity에서 확장됩니다.
DialogFragmente dialogFragment= new MyDialogFragmentClass()
DialogFragment.show(getSupportFragmentManager(),"My Dialog")
오류가 발생합니다. 그래서 내 질문은 어떻게 내 클래스 AppCompatPreferenceActivity에서 확장하는 경우 해당 메서드를 사용할 수 있습니다.
대신 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();
}
}
감사합니다!
https://stackoverflow.com/questions/25887373/calling-dialogfragment-from을 -fragment-not-fragmentactivity –
'오류가 발생합니다 '라는 오류가 표시됩니다. –
링크가 내 질문을 해결하지 못했습니다. 주요 문제는 getSupportFragmentManager() 메서드가 필요하지만 AppCompatPreferenceActivity를 확장 할 수 있기 때문입니다. –