首页 > 解决方案 > 弹出窗口未显示在android的片段中

问题描述

嗨,在下面的代码中,我在我的片段中实现了没有 onclicklistner 的弹出窗口。从活动移动到片段想要显示弹出窗口,但没有显示弹出窗口。

谁能帮我在哪里做错了

活动.java:

Fragment fragment = new HomeNurseFragment();
        Bundle args = new Bundle();
        args.putSerializable("myHospitalList", myList);
        fragment.setArguments(args);
        loadFragment(fragment);

HomeFragment.java:

 LayoutInflater layoutInflater = (LayoutInflater)getActivity().getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);  View customView = layoutInflater.inflate(R.layout.popup_hospitallist, null);
            View popupView = layoutInflater.inflate(R.layout.popup_hospitallist, null);
            final PopupWindow popupWindow = new PopupWindow(
                    popupView,
                    ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
                    Button save = popupView.findViewById(R.id.save);
                    Button cancel = popupView.findViewById(R.id.cancel);
                    Button close = popupView.findViewById(R.id.close);
                    MaterialSpinner hospital = customView.findViewById(R.id.hospital);
                    hospital.setHint(Html.fromHtml(hospital.getHint() + " " + "<font color=\"#ff0000\">" + "* " + "</font>"));
                    hospital.setAdapter(spinnerArrayAdapter);
                    popupWindow.setTouchable(true);
                    popupWindow.setBackgroundDrawable(new ColorDrawable(
                            android.graphics.Color.TRANSPARENT));
                    popupWindow.showAtLocation(customView, Gravity.CENTER, 0, 0);
                    popupWindow.setTouchInterceptor(new View.OnTouchListener() {
                        @Override
                        public boolean onTouch(View v, MotionEvent event) {
                            return false;
                        }
                    });
                    close.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            popupWindow.dismiss();
                        }
                    });

                }

标签: androidandroid-fragmentspopup

解决方案


推荐阅读