如何显示"装载"在Android的状态? [英] How to show "Loading" status in Android?

查看:148
本文介绍了如何显示"装载"在Android的状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做一个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?

在此先感谢!

推荐答案

使用异步任务为你的状态。

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

这篇关于如何显示&QUOT;装载&QUOT;在Android的状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆