如何显示“正在加载"在安卓中的状态? [英] How to show "Loading" status in Android?

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

问题描述

我正在制作一个 Android 应用程序,它必须通过 Internet 加载一些数据(只有一些数据——不是全部).因此,当数据正在加载,而 Internet 连接速度较慢时,我想向用户显示正在加载..."图标.

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?

提前致谢!

推荐答案

使用 Async Task 处理您的状态.

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

这篇关于如何显示“正在加载"在安卓中的状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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