Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show "Loading" status in Android?

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!

like image 357
Roshnal Avatar asked Feb 23 '12 05:02

Roshnal


People also ask

How do I see progress on android?

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);

How to show Spinner in android?

In order to use that, you just need to define it in the xml like this. spinner. setVisibility(View. GONE); spinner.

Which view is used to displays loading 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.


1 Answers

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();
    }
}
like image 60
Padma Kumar Avatar answered Sep 30 '22 03:09

Padma Kumar