Answer the question
In order to leave comments, you need to log in
Accessing ProgressBar from AsyncTask?
There is something like this code:
class DownloadEventData
{
private Integer i1;
private Integer i2;
public DownloadEventData(Integer i1 , Integer i2)
{
this.i1 = i1;
this.i2 = i2;
}
Тут геттеры и сеттеры
}
class DownloadTask extends AsyncTask<String,DownloadEventData,Integer>
{
private ProgressBar pb;
public void setPb(ProgressBar p)
{
this.pb = p;
}
@Override
protected String doInBackground(String... params) {
...
publishProgress(new DownloadEventData([сколько скачалось],[сколько всего качать]));
...
}
@Override
protected void onProgressUpdate(DownloadEventData...values) {
this.pb.setMax(values[0].getI2);
this.pb.setProcess(values[0].getI1);
super.onProgressUpdate(values);
}
//---------------------------------------------------------------
protected void onPreExecute(Integer result)
{
super.onPreExecute();
}
@Override
protected void onPostExecute(Integer result)
{
}
}
ProgressBar ppp = (ProgressBar) findViewById(R.id.progressbar);
DownloadTask dt = new DownloadTask();
dt.setPd(ppp);
dt.execute("http://yandex.ru");
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ProgressBar.setMax(int)' on a null object reference
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question