我有同樣的問題。我有PopupWindow帶按鈕(R.id.imageView1)。我對該按鈕有回調。當彈出窗口被忽略時,我註銷回調(popupWindow.setOnDismissListener)。
奇怪的是,在調試模式下不會發生警告消息。
PopupWindow popupWindow;
@Override
public void onCreate(Bundle savedInstanceState) {
//layout for popup window
LayoutInflater layoutInflater= (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.grid, null);
popupWindow = new PopupWindow(
popupView,
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
}
public void showPopup(View view) {
final View popupView=popupWindow.getContentView();
popupView.findViewById(R.id.imageView1).setOnClickListener(new PopupOnClickListener(popupWindow,this));
//required if I want popup to close on click outside popup area
popupWindow.setOutsideTouchable(true);
popupWindow.setBackgroundDrawable(new BitmapDrawable());
popupWindow.showAsDropDown(view, 50, -30);
popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
@Override
public void onDismiss() {
popupView.findViewById(R.id.imageView1).setOnClickListener(null);
}
});
}
你想與「關我的onCreate()方法太早」說什麼?彈出窗口在onCreate完成後執行。 – jonathanrz