Android popup popup by oncreate

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);

}

      

an exception thrown when calling loadingPopup()

from method oncreate()

.. please help me

+3
android popupwindow


source to share


1 answer


You are trying to show the popup even before the activity window is displayed. With the post method, we can wait for all the required lifecycle methods to complete.

Try the following:



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);
        }
    });
}

      

+9


source to share







All Articles
Loading...
X
Show
Funny
Dev
Pics