Best way to show a loading/progress indicator?

Jochem Gruter picture Jochem Gruter · Oct 11, 2012 · Viewed 182.9k times · Source

What is the best way to show a loading spinner while the app is waiting for a response from the server?

Can this be done programmatically? So that I don't have to add the load spinner in the xml file?

Answer

Suraj Bajaj picture Suraj Bajaj · Oct 11, 2012

ProgressDialog is deprecated from Android Oreo. Use ProgressBar instead

ProgressDialog progress = new ProgressDialog(this);
progress.setTitle("Loading");
progress.setMessage("Wait while loading...");
progress.setCancelable(false); // disable dismiss by tapping outside of the dialog
progress.show();
// To dismiss the dialog
progress.dismiss();

OR

ProgressDialog.show(this, "Loading", "Wait while loading...");

Read more here.

By the way, Spinner has a different meaning in Android. (It's like the select dropdown in HTML)