popupwindow引用xml文件做弹窗
为什么我把spinner下拉列表的xml页,以popupwindow引用到新的页面当中做弹窗之后,下拉列表就失效了呢?
相关代码:
private void showPopupWindow(){ //设置contentview View contentView = LayoutInflater.from(TransportIntoActivity.this).inflate(R.layout.fragment_transport_into_deposit,null); mPopWindow = new PopupWindow(contentView, 450,1005,true); mPopWindow.setContentView(contentView); adapter01 = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,bingxiang); adapter02 = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,cengshu); adapter03 = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, chouti); adapter04 = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item,heshu); //将adapter 添加到spinner中 spinner01.setAdapter(adapter01); spinner02.setAdapter(adapter02); spinner03.setAdapter(adapter03); spinner04.setAdapter(adapter04); //添加事件Spinner事件监听 spinner01.setOnItemSelectedListener(new SpinnerSelectedListener()); spinner02.setOnItemSelectedListener(new SpinnerSelectedListener()); spinner03.setOnItemSelectedListener(new SpinnerSelectedListener()); spinner04.setOnItemSelectedListener(new SpinnerSelectedListener()); //设置默认值 spinner01.setVisibility(View.VISIBLE); spinner02.setVisibility(View.VISIBLE); spinner03.setVisibility(View.VISIBLE); spinner04.setVisibility(View.VISIBLE); //显示PopupWindow View rootview = LayoutInflater.from(TransportIntoActivity.this).inflate(R.layout.activity_transport_into,null); mPopWindow.showAtLocation(rootview, Gravity.CENTER,0,0); }
6
收起
正在回答
1回答
同学你好,查看一下是不是引用错了,同学引用的是contentView对象,对应的是R.layout.fragment_transport_into_deposit文件。祝:学习愉快
1.Android 零基础入门
- 参与学习 人
- 提交作业 1789 份
- 解答问题 2907 个
Android大楼Java起,本阶段是Android攻城狮培养计划的第一部分语法与界面基础篇,将带大家从0开始入门Android开发。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星