Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android popup window call from 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);

}

when invoke the method loadingPopup() from oncreate() an exception accrued .. please can you help me

like image 512
abed Avatar asked Dec 06 '25 17:12

abed


1 Answers

You are trying to show the pop-up window even before the activity window has been displayed. With the help of post method we can wait until all necessary start up life cycle methods get completed.

Try this :

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);
        }
    });
}
like image 107
Sourab Sharma Avatar answered Dec 08 '25 06:12

Sourab Sharma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!