Master da Web
Back to Blog

Android Loading ProgressDialog

LucasFebruary 24, 20171 min readUpdated on November 4, 2023
Android Loading ProgressDialog

public class LoadingHelper {

    private static ProgressDialog progress;

    public void run(Context context, final CallbackInterface callback){
        progress = ProgressDialog.show(context, "Carregando",
                "Por favor, aguarde :D", true);

        new Thread(new Runnable() {
            @Override
            public void run()
            {
                if(callback != null)
                    callback.run();
            }
        }).start();
    }

    public static void dismiss(){
        progress.dismiss();
    }


    public interface CallbackInterface
    {
        public void run ();
    }
}

Then to display the ProgressDialog:

LoadingHelper.run(context, null);

// Ou usando a função de callback

LoadingHelper.run(context, new CallbackInterface(){

@Override
void run(){
    
}

});

To hide the ProgressDialog:

LoadingHelper.dismiss();

 

 

Tags#ProgressDialog
Share

Need Hosting or Servers?

Discover our VPS, dedicated servers and professional hosting solutions

Related Articles

View all articles