带片段的自定义对话框:找不到片段ID的视图

时间:2019-04-29 10:29:01

标签: java android android-fragments

我正在尝试创建一个包含两个Fragments

的自定义对话框
 public void showFragments(final String input) {
            if (getActivity() != null && isAdded()) {
                final Dialog myDialog = new Dialog(getActivity());
                myDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                assert myDialog.getWindow() != null;
                myDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
                View view  = getActivity().getLayoutInflater().inflate(R.layout.text_dialog, null);
                myDialog.setContentView(view);
                myDialog.setCancelable(true);
                final Button stylishtext = view.findViewById(R.id.stylishtext);
                Button decorations = view.findViewById(R.id.decoration);
                /*by default*/
                StylistFragment stylistFragment = new StylistFragment();
                if (getActivity() != null) {
                    FragmentTransaction fragmentTransaction = getChildFragmentManager().beginTransaction();
                    fragmentTransaction.replace(R.id.framelayout, stylistFragment, stylistFragment.getTag());
                    Bundle bundle = new Bundle();
                    bundle.putString("input", input);
                    stylistFragment.setArguments(bundle);
                    fragmentTransaction.commit();
                }
                stylishtext.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        StylistFragment stylistFragment = new StylistFragment();
                        if (getActivity() != null) {
                            FragmentTransaction fragmentTransaction = getChildFragmentManager().beginTransaction();
                            fragmentTransaction.replace(R.id.framelayout, stylistFragment, stylistFragment.getTag());
                            Bundle bundle = new Bundle();
                            bundle.putString("input", input);
                            stylistFragment.setArguments(bundle);
                            fragmentTransaction.commit();
                        }
                    }
                });
                decorations.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        DecorateFragment decorateFragment = new DecorateFragment();
                        if (getActivity() != null) {
                            FragmentTransaction fragmentTransaction = getChildFragmentManager().beginTransaction();
                            fragmentTransaction.replace(R.id.framelayout, decorateFragment, decorateFragment.getTag());
                            Bundle bundle = new Bundle();
                            bundle.putString("input", input);
                            decorateFragment.setArguments(bundle);
                            fragmentTransaction.commit();
                        }
                    }
                });
                if (getActivity() != null && !getActivity().isFinishing()) {
                    myDialog.show();
                }
            }
        }

但我收到此消息:

  

java.lang.IllegalArgumentException:找不到ID为0x7f09013f的视图   (maa.myapp:id / framelayout)片段StylistFragment {1e3aeb#0   id = 0x7f09013f}

id framelayout存在于自定义对话框xml不是 StylistFragment

我只想在自定义对话框中显示2个片段,有人可以帮我解决这个问题。

0 个答案:

没有答案