I'm making an Android application and it has to load some data though Internet (only some data-- not all). So when the data is loading, and the Internet connection is slow, I want to show a "Loading..." icon to the user.
So how can I do this? Show a "Loading..." icon while the data is being loaded in the background, and when its completely loaded, hide the icon?
Thanks in advance!
In android there is a class called ProgressDialog that allows you to create progress bar. In order to do this, you need to instantiate an object of this class. Its syntax is. ProgressDialog progress = new ProgressDialog(this);
In order to use that, you just need to define it in the xml like this. spinner. setVisibility(View. GONE); spinner.
In android, ProgressBar is a user interface control that is used to indicate the progress of an operation such as downloading a file, uploading a file. The android ProgressBar comes in two shapes Horizontal ProgressBar and Spinner ProgressBar.
use Async Task for your status.
new SomeTask(0).execute();
/** Inner class for implementing progress bar before fetching data **/
private class SomeTask extends AsyncTask<Void, Void, Integer>
{
private ProgressDialog Dialog = new ProgressDialog(yourActivityClass.this);
@Override
protected void onPreExecute()
{
Dialog.setMessage("Doing something...");
Dialog.show();
}
@Override
protected Integer doInBackground(Void... params)
{
//Task for doing something
return 0;
}
@Override
protected void onPostExecute(Integer result)
{
if(result==0)
{
//do some thing
}
// after completed finished the progressbar
Dialog.dismiss();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With