private void loadingPopup() {
LayoutInflater inflater = this.getLayoutInflater();
View layout = inflater.inflate(R.layout.loading_dialog, null);
PopupWindow windows = new PopupWindow(layout , 300,300,true);
windows.setFocusable(false);
windows.setTouchable(true);
windows.setOutsideTouchable(true);
windows.showAtLocation(layout,Gravity.CENTER, 0, 0);
}
从loadingPopup()
调用方法oncreate()
时产生的异常..请帮助我
答案 0 :(得分:9)
即使在显示活动窗口之前,您也试图显示弹出窗口。 在post方法的帮助下,我们可以等到所有必要的启动生命周期方法完成。
试试这个:
private void loadingPopup() {
LayoutInflater inflater = this.getLayoutInflater();
final View layout = inflater.inflate(R.layout.loading_dialog, null);
final PopupWindow windows = new PopupWindow(layout , 300,300,true);
windows.setFocusable(false);
windows.setTouchable(true);
windows.setOutsideTouchable(true);
layout.post(new Runnable() {
public void run() {
windows.showAtLocation(layout,Gravity.CENTER, 0, 0);
}
});
}