android - 弹出窗口未显示在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();
}
});
}
解决方案
推荐阅读
- docker - 我无法运行我的 reactjs 应用程序的 docker 容器
- laravel - 如何保护 Vue.js 和 Laravel 中的前端路由?
- powerbi - 如何集中 Power BI Web 的数据源连接设置?
- scala - 如何在apache spark中将RDD [ParentClass]与RDD [Subclass]匹配?
- i2c - 在 esp32 上为 i2c 设置自定义引脚
- linux - /proc/vmstat 中的 NUMA 信息
- python - Keras - 具有多个输入过滤器的 cnn
- javascript - 尝试使用 nodeJS 和 CheerIO 进行网络抓取
- r - R - 使用分布从矩阵中随机抽样以表示每列中零的数量 - 分层抽样
- php - 如何在多租户 laravel 应用程序中锁定租户用户之间的访问