0

I have a progessbar in an activity but the Async is in an external .class-File How do i refer to that progessbar in the async task?

i use a slightly changed version of the AsyncTask from Download a file with Android, and showing the progress in a ProgressDialog

Community
  • 1
  • 1
malger
  • 173
  • 1
  • 2
  • 7

1 Answers1

0

You can add a setter method in the asyncTask class like this:

public class MyTask extends asyncTask .... {
     private ProgressBar bar;
     public void setProgressBar(ProgressBar bar){
              this.bar = bar;
        }
 }

then from the activity when creating a new asyncTask just set the progress bar. something like this:

public class MyActivity extends Activity{
  private ProgressBar bar;
  private myTask task;


 void createTask(){
   myTask = new MyTask(....);
   myTask.setProgressBar(bar);
   }
}
Mr.Me
  • 9,192
  • 5
  • 39
  • 51