如何添加ProgressDialog [英] How to add ProgressDialog

查看:124
本文介绍了如何添加ProgressDialog的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下载从收存箱被采取在几秒钟的文件。我想补充一个 ProgressDialog 的下载,但我不知道该怎么做。

 公共类DownloadFile扩展的AsyncTask<虚空龙,布尔> {
    DownloadFile(上下文的背景下,DropboxAPI<>马屁,字符串dropboxpath,字符串sdpath,诠释POS,int类型,ArrayList的<字符串>文件夹)抛出DropboxException {
        FileOutputStream中mFos;
        档案文件=新的文件(sdpath);
        字符串路径= dropboxpath;
        尝试{
            mFos =新的FileOutputStream(文件);
            mApi.getFile(路径,空,mFos,NULL);
        }赶上(例外五){
            // TODO:处理异常
        }
    }

    @覆盖
    保护布尔doInBackground(空... PARAMS){
        // TODO自动生成方法存根
        返回null;
    }
}
 

解决方案

做这种方式:

 公开最后一类DownloadFile扩展的AsyncTask<虚空龙,布尔> {

私人上下文的背景下;
私人ProgressDialog progressDialog;

公共DownloadFile(上下文的背景下){
    this.context =背景;
}

/ *
 * @see android.os.AsyncTask#在preExecute()
 * /
@覆盖
在preExecute保护无效(){
    尝试 {
        progressDialog = ProgressDialog.show(上下文,,消息,真);
    }赶上(最终的Throwable日){
        //去做
    }
}

/ *
 * @see android.os.AsyncTask#doInBackground(PARAMS [])
 * /
@覆盖
保护布尔doInBackground(虚空......为arg0){
    //做一点事
}

    @覆盖
保护无效onProgressUpdate(字符串...进度){
    //做一点事
    super.onProgressUpdate(进度);
}

/ *
 * @see android.os.AsyncTask#onPostExecute(java.lang.Object中)
 * /
@覆盖
保护无效onPostExecute(布尔结果){
    progressDialog.dismiss();
}}
 

I am downloading a file from dropbox which is taking a few seconds. I want to add a ProgressDialog for the download but I don't know how to do that.

public class DownloadFile extends AsyncTask<Void, Long, Boolean> {
    DownloadFile(Context context ,DropboxAPI<?> mApi ,String dropboxpath,String   sdpath,int pos,int s,ArrayList<String> folder) throws DropboxException {
        FileOutputStream mFos;
        File file=new File(sdpath);
        String path = dropboxpath;
        try{
            mFos = new FileOutputStream(file);
            mApi.getFile(path, null, mFos, null);
        }catch (Exception e) {
            // TODO: handle exception
        }
    } 

    @Override
    protected Boolean doInBackground(Void... params) {
        // TODO Auto-generated method stub
        return null;
    }   
}

解决方案

Do it this way:

public final class DownloadFile extends AsyncTask<Void, Long, Boolean> {

private Context context;
private ProgressDialog progressDialog;

public DownloadFile (Context context) {
    this.context = context;
}

/* 
 * @see android.os.AsyncTask#onPreExecute()
 */
@Override
protected void onPreExecute() {
    try {
        progressDialog = ProgressDialog.show(context, "", "message", true);
    } catch (final Throwable th) {
        //TODO
    }
}

/* 
 * @see android.os.AsyncTask#doInBackground(Params[])
 */
@Override
protected Boolean doInBackground(Void... arg0) {
    //do something
}

    @Override
protected void onProgressUpdate(String... progress) {
    //do something
    super.onProgressUpdate(progress);
}

/* 
 * @see android.os.AsyncTask#onPostExecute(java.lang.Object)
 */
@Override
protected void onPostExecute(Boolean result) {
    progressDialog.dismiss();
} }

这篇关于如何添加ProgressDialog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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