我的布局文件夹中有一个LinearLayout,名为“settings_caching_popup.xml”我试图在onOptionsItemSelected(MenuItem item)
方法中显示弹出窗口的布局。但findViewById(R.layout.settings_caching_popup)
返回始终为空。然后我将xml Layout中的ID设置为LinearLayout,其中android:id="@+id/settings_caching_popup
和findViewById(R.id.settings_caching_popup)
。返回值也为null。android findViewById在onoptionsitemselected中返回null
拔出了onOptionsItemSelected(MenuItem item)
的:
PopupWindow popUp = new PopupWindow(context);
LinearLayout ll = (LinearLayout) findViewById(R.layout.settings_caching_popup);
popUp.setContentView(ll);
popUp.showAtLocation(ll, Gravity.BOTTOM, 10, 10);
popUp.update(50, 50, 300, 80);
方法'findViewById'正在寻找一个元素在活动的视图内, – bogdan