不要使用PopupWindow默认构造方法

// declare view, width, height ...
PopupWindow popupWindow = new PopupWindow();
popupWindow.setContentView(view);
popupWindow.setWidth(width);
popupWindow.setHeight(height);

上面这段代码在Android 4.0 真机(ZTE V889D)调试没有问题,但是在Android 2.2模拟器上使用,就会报运行时异常和空指针异常,改用下面的代码没有问题:

// declare view, width, height ...
PopupWindow popupWindow = new PopupWindow(view, width, height);

所以,为了兼容性,不要使用PopupWindow默认构造方法。

posted @ 2012-11-16 12:35  tt-0411  阅读(1852)  评论(0编辑  收藏  举报