0

Программа выбрасывает исключение android.util.AndroidRuntimeException: requestFeature() must be called before adding content когда я вызываю DialogFragment на старых версиях Android, заметил на API 21 и на API 17

public class ServerConnectionDialog extends DialogFragment {
    private String message;
    private Button ok;
    private CircularProgressBar progressBar;
    TextView txt;
    private int code;
    public static ServerConnectionDialog newInstance(String message) {
        Bundle args = new Bundle();
        args.putString("message",message);
        ServerConnectionDialog fragment = new ServerConnectionDialog();
        fragment.setArguments(args);
        return fragment;
    }



    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if(getArguments()!=null){
            message=getArguments().getString("message");
        }
    }

    @NonNull
    @Override
    public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
        AlertDialog.Builder builder=new AlertDialog.Builder(getActivity());
        LayoutInflater layoutInflater=getActivity().getLayoutInflater();
        View v=layoutInflater.inflate(R.layout.status_server_dialog,null);
        builder.setCancelable(true);
        ok=v.findViewById(R.id.buttonOk); 
        txt=v.findViewById(R.id.txt);
        progressBar=v.findViewById(R.id.progressbar);
        ok.setVisibility(View.GONE);
        progressBar.setVisibility(View.VISIBLE);
        ok.setVisibility(View.GONE);
        txt.setText(message);
        builder.setView(v);
        return builder.create();
    }



    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.status_server_dialog, container, true);
        setCancelable(false);
        return view;
    }
}

Создаю и показываю DialogFragment

ServerConnectionDialog serverConnectionDialog=ServerConnectionDialog.newInstance(getResources().getString(R.string.string_connect));
        serverConnectionDialog.showNow(getSupportFragmentManager(),ServerConnectionDialog.class.getSimpleName());

1 ответ 1

0

Убрал

 @Nullable
        @Override
        public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
            View view = inflater.inflate(R.layout.status_server_dialog, container, true);
            setCancelable(false);
            return view;
        }

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.