Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 实现ProgressDialog异步任务_Android_Android Asynctask_Progressdialog - Fatal编程技术网

Android 实现ProgressDialog异步任务

Android 实现ProgressDialog异步任务,android,android-asynctask,progressdialog,Android,Android Asynctask,Progressdialog,在扩展AsyncTask的类中实现ProgressDialog时遇到问题 我遇到了以下问题: super.onProgressUpdate(进度) 来自eclipse的消息:类型AsyncTask中的onProgessUpdate(Void…)方法不适用于参数(整数[]) 有什么解决办法吗 static class BitmapWorkerTask extends AsyncTask <int[], Void, Bitmap[]> { private int[] d

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

我遇到了以下问题:

super.onProgressUpdate(进度)

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

有什么解决办法吗

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();
        }  
}
静态类BitmapWorkerTask扩展了AsyncTask{
私有int[]数据;
私人int宽度、高度;
私有整数屏幕宽度;
私人室内屏幕高度;
私人国际nmbrOfImages;
私有int[]imgRes,textRes;
私有字符串[]滚动文本;
私有ImageView[]ImageView;
私有文本视图[]文本视图;
私人视野;
私营平地机厂;
私有AlertDialog.Builder alertadd;
私人语境;
私人WeakReference sc;
私有weakreferencebitmapv;
公共位图工作任务(int-nmbrOfImages,字符串[]滚动文本,上下文){
this.nmbrOfImages=nmbrOfImages;
this.scrollText=滚动文本;
this.context=上下文;
视图=空;
factory=null;
alertadd=null;
gc();
sc=新的WeakReference(上下文);
试一试{
对于(int i=0;i
将类初始化更改为


静态类BitmapWorkerTask扩展AsyncTask{

将fiesr行更改为

static class BitmapWorkerTask extends AsyncTask <Integer[], Void, Bitmap[]>
静态类BitmapWorkerTask扩展了AsyncTask

将异步任务更改为:

static class BitmapWorkerTask extends AsyncTask <int[], Integer, Bitmap[]>
静态类BitmapWorkerTask扩展了AsyncTask

您不能将
原语
数据类型
int[]
作为
异步任务
中的参数传递。您需要传递
包装器
数据类型。将其更改为
静态类BitmapWorkerTask扩展异步任务
@Kaidul Islam Sazal:传递数据类型int[]在实现ProgressDialog之前,作为AsyncTask中的一个参数,我遵循了Nargis的示例,现在我看到的是错误消息消失了。