0

I have this code to create a progress bar , but I doesn't have a cancel method how to solve this problem?

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));
}
Twisty Toon
  • 31
  • 1
  • 1
  • 3

1 Answers1

1

Just hide the Progressbar using setVisibility method after your task is completed and provide the parameter VIEW.GONE. Progressbar does not have cancel method.

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
Psypher
  • 10,717
  • 12
  • 59
  • 83
  • it ok, but in my work i want button to cancel this because if user doesn't want to download user can use this button to stop download. thank you regret. – Twisty Toon Jul 16 '15 at 06:11
  • K..In that case you have to create a custom dialog with a cancel button. When the cancel is clicked you can add your logic to cancel the download. – Psypher Jul 16 '15 at 11:15