skip to Main Content

I am trying to show a dialog while my method is executing. The problem is that the dialog shows when the method end is reached. How is it possible to show it, as soon as I call loadingDialog.show() ?

    public void test(View v){
    loadingDialog = new LoadingDialog(this);
    loadingDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));

    loadingDialog.show();

    //......
    }

2

Answers


  1. If you want to do that, you need to either launch a thread or a Kotlin coroutine so the actual work can be done in the background.

    Login or Signup to reply.
  2. Did you tried putting the dialog’s code in another method and call that method at the beggining of the test method? Like:

    private void callDialog(){
    loadingDialog = new LoadingDialog(this);
    loadingDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
    
    loadingDialog.show();
    }
    
    public void test(View v){
    callDialog();
    //......
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search