Reputation: 3833
I am having a problem to implement a ProgressDialog in a class that extends AsyncTask.
I got the following problem:
super.onProgressUpdate(progress);
message from eclipse: the method onProgessUpdate (Void...) in the type AsyncTask is not applicable to the arguments (Integer[])
Any solutions?
static class BitmapWorkerTask extends AsyncTask <int[], Void, Bitmap[]> {
private int[] data;
private int width, height;
private int screenWidth;
private int screenHeight;
private int nmbrOfImages;
private int[] imgRes, textRes;
private String[] scrollText;
private ImageView[] imageView;
private TextView[] textView;
private View view;
private LayoutInflater factory;
private AlertDialog.Builder alertadd;
private Context context;
private WeakReference <Context> sc;
private WeakReference <Bitmap[]> bitmapV;
public BitmapWorkerTask(int nmbrOfImages, String[] scrollText, Context context) {
this.nmbrOfImages = nmbrOfImages;
this.scrollText = scrollText;
this.context = context;
view = null;
factory = null;
alertadd = null;
System.gc();
sc = new WeakReference <Context> (context);
try {
for (int i = 0; i < scaledBitmap.length; i++) {
scaledBitmap[i].recycle();
scaledBitmap[i] = null;
}
} catch (NullPointerException ne) {
System.out.println("nullpointerexception ... gick inte recycla bitmapbilder");
}
data = new int[nmbrOfImages];
imageView = new ImageView[nmbrOfImages];
textView = new TextView[nmbrOfImages];
}
@Override
protected Bitmap[] doInBackground(int[] ... params) {
data = params[0];
alertadd = new AlertDialog.Builder(sc.get());
factory = LayoutInflater.from(sc.get());
// Ta reda på skärmens dimensioner.
DisplayMetrics metrics = context.getResources().getDisplayMetrics(); // Beräkna skärmens dimensioner.
screenWidth = metrics.widthPixels;
screenHeight = metrics.heightPixels;
width = ((int)(this.screenWidth * 1));
height = (int)(width * 1.5);
Bitmap[] bm = decodeSampledBitmapFromResource(sc.get().getResources(), data, width, height);
bitmapV = new WeakReference <Bitmap[]> (bm);
view = factory.inflate(R.layout.scrollview, null);
imgRes = new int[] {R.id.img1, R.id.img2, R.id.img3, R.id.img4, R.id.img5, R.id.img6, R.id.img7, R.id.img8, R.id.img9};
textRes = new int[] {R.id.text_img1, R.id.text_img2, R.id.text_img3, R.id.text_img4, R.id.text_img5, R.id.text_img6,
R.id.text_img7, R.id.text_img8, R.id.text_img9};
for (int i = 0; i < nmbrOfImages; i ++) {
imageView[i] = (ImageView) view.findViewById(imgRes[i]);
textView[i] = (TextView) view.findViewById(textRes[i]);
}
return bitmapV.get();
}
protected void onPostExecute(Bitmap[] bitmap) {
for (int i = 0; i < nmbrOfImages; i++) {
imageView[i].setImageBitmap(bitmap[i]);
textView[i].setText(Html.fromHtml(scrollText[i]));
textView[i].setVisibility(TextView.VISIBLE);
}
loadAlertDialog();
}
/**
* Updating progress bar
* */
protected void onProgressUpdate(Integer ... progress) {
// setting progress percentage
super.onProgressUpdate(progress);
progressBar.setProgress(0);
progressBar.setProgress(progress[0]);
}
private void startProgressBar() {
progressBar = new ProgressDialog(context);
progressBar.setCancelable(true);
progressBar.setMessage("File downloading ...");
progressBar.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressBar.setProgress(0);
progressBar.setMax(100);
progressBar.show();
}
}
Upvotes: 0
Views: 290
Reputation: 4787
Change your Async Task to :
static class BitmapWorkerTask extends AsyncTask <int[], Integer, Bitmap[]>
Upvotes: 0
Reputation: 18509
Change your fiesr line to this
static class BitmapWorkerTask extends AsyncTask <Integer[], Void, Bitmap[]>
Upvotes: 1
Reputation: 21117
Change your class initialization to this
static class BitmapWorkerTask extends AsyncTask {
Upvotes: 0