Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/220.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android异步任务对话框循环_Android - Fatal编程技术网

android异步任务对话框循环

android异步任务对话框循环,android,Android,今天我搜索了一整天,试图找到一些示例代码或教程,介绍如何在任务完成时创建循环进度。完成此任务的时间会相应变化,并且有很多示例正在使用线程。睡眠(xxxx)使其循环,但这不是有效的。下面是我想做的,我想加载一个ListView,单击按钮后使用JSON从web服务填充该ListView。listview加载得非常好,但根据大小,加载大约需要5-10秒,因此我想在用户等待时显示旋转的圆圈。有人能分享一些关于如何实现这一点的示例代码吗 谢谢您可以尝试以下代码 progDailog = ProgressD

今天我搜索了一整天,试图找到一些示例代码或教程,介绍如何在任务完成时创建循环进度。完成此任务的时间会相应变化,并且有很多示例正在使用线程。睡眠(xxxx)使其循环,但这不是有效的。下面是我想做的,我想加载一个ListView,单击按钮后使用JSON从web服务填充该ListView。listview加载得非常好,但根据大小,加载大约需要5-10秒,因此我想在用户等待时显示旋转的圆圈。有人能分享一些关于如何实现这一点的示例代码吗


谢谢

您可以尝试以下代码

progDailog = ProgressDialog.show(loginAct,"Process ", "please wait....",true,true);

new Thread ( new Runnable()
{
     public void run()
     {
      // your code goes here
     }
}).start();

 Handler progressHandler = new Handler() 
 {

     public void handleMessage(Message msg1) 
     {

         progDailog.dismiss();
         }
 }
newload().execute()调用

class Load extends AsyncTask<String, String, String> {
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            ProgressDialog progDailog = new ProgressDialog(Activity.this);
            progDailog.setMessage("Loading...");
            progDailog.setIndeterminate(false);
            progDailog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
            progDailog.setCancelable(true);
            progDailog.show();
        }
        @Override
        protected String doInBackground(String... aurl) {
            //do something while spinning circling show
            return null;
        }
        @Override
        protected void onPostExecute(String unused) {
            super.onPostExecute(unused);
            progDailog.dismiss();
        }
    }
类加载扩展异步任务{
@凌驾
受保护的void onPreExecute(){
super.onPreExecute();
ProgressDialog progDailog=新建ProgressDialog(Activity.this);
setMessage(“正在加载…”);
progDailog.setUndeterminate(false);
progDailog.setProgressStyle(ProgressDialog.STYLE_微调器);
progDailog.setCancelable(真);
progDailog.show();
}
@凌驾
受保护的字符串背景(字符串…aurl){
//旋转旋转时做些什么
返回null;
}
@凌驾
受保护的void onPostExecute(字符串未使用){
super.onPostExecute(未使用);
progDailog.disclose();
}
}

如果你找到了答案,我的答案对你有帮助。请勾选一个已接受的答案。请在我的答案左边打勾,然后请在左边打勾。关于ProgressDialog(Activity.this);在类中,Load给出了一个错误。当然我们必须使用什么?@Boris Karloff您必须使用异步任务所在活动的名称。如果这个从AsyncTask扩展而来的私有类“Load”在类“MainActivity”中,那么您必须使用“ProgressDialog(MainActivity.this)”。
private class LoadAssync extends AsyncTask<String, Void, Void> {



    protected void onPreExecute() {

        ProgressDialog dialog;
                   dialog.setMessage("Loading...");
    dialog.show();
    }

    protected Void doInBackground(final String... args) {
        // you can do the code here
        return null;


    }

    protected void onPostExecute(final Void unused) {

        if (dialog.isShowing()) {
            dialog.dismiss();
        }

    }
}
 LoadAssync mAsyync=new LoadAssync();
 mAsyync.execute(null);