3
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()..请你帮帮我

4

1 回答 1

11

您甚至在显示活动窗口之前尝试显示弹出窗口。在 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);
        }
    });
}
于 2013-02-06T14:05:11.883 回答