Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
193 views
in Technique[技术] by (71.8m points)

java - 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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...