【问题标题】:How to create cancel method in download progress bar?如何在下载进度栏中创建取消方法?
【发布时间】:2015-07-16 05:09:28
【问题描述】:

我有这个创建进度条的代码,但是我没有cancel方法怎么解决这个问题?

void showProgress(String file_path) {
    dialog = new Dialog(DownloadFileDemo1.this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.myprogressdialog);
    dialog.setTitle("Download Progress");


    TextView text = (TextView) dialog.findViewById(R.id.tv1);

    text.setText("Downloading file from ... " + file_path);
    cur_val = (TextView) dialog.findViewById(R.id.cur_pg_tv);
    cur_val.setText("Starting download...");
    dialog.show();


    pb = (ProgressBar) dialog.findViewById(R.id.progress_bar);
    pb.setProgress(0);
    pb.setProgressDrawable(getResources().getDrawable(R.drawable.green_progress));
}

【问题讨论】:

标签: android android-alertdialog progressdialog


【解决方案1】:

只需在任务完成后使用setVisibility 方法隐藏Progressbar 并提供参数VIEW.GONEProgressbar 没有取消方法。

pb = (ProgressBar) dialog.findViewById(R.id.progress_bar);
pb.setProgress(0);
pb.setProgressDrawable(getResources().getDrawable(R.drawable.green_progress));
pb.setVisibility(View.GONE);  //This line added

【讨论】:

  • 没关系,但在我的工作中我希望按钮取消它,因为如果用户不想下载用户可以使用此按钮停止下载。谢谢你的遗憾。
  • K..在这种情况下,您必须创建一个带有取消按钮的自定义对话框。单击取消后,您可以添加逻辑以取消下载。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-09
相关资源
最近更新 更多