0

我在扩展 AsyncTask 的类中实现 ProgressDialog 时遇到问题。

我遇到了以下问题:

super.onProgressUpdate(进度);

来自 Eclipse 的消息:AsyncTask 类型中的方法 onProgessUpdate (Void...) 不适用于参数 (Integer[])

有什么解决办法吗?

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();
        }  
}
4

3 回答 3

1

将您的 fisr 行更改为此

static class BitmapWorkerTask extends AsyncTask <Integer[], Void, Bitmap[]>
于 2013-08-12T10:30:08.153 回答
0

将您的异步任务更改为:

static class BitmapWorkerTask extends AsyncTask <int[], Integer, Bitmap[]>
于 2013-08-12T10:32:30.243 回答
0

将您的类初始化更改为此

静态类 BitmapWorkerTask 扩展 AsyncTask {

于 2013-08-12T10:29:30.373 回答