更新asynctask中的进度条数组

时间:2014-03-12 09:22:19

标签: android android-asynctask android-progressbar

我有一个asynctask,我在其中传递progressbars数组作为参数。在doinbackground方法中,我计算每个进度条的进度,并以进度作为参数调用PublishProgress。这就是我的表现:

static volatile int currentProgressBarIndex;

@Override
    protected Integer doInBackground(String... arg0) {
        // TODO Auto-generated method stub
        // display the images in now playing
        while (ScheduleManager.isScheduleRunning) {
            Iterator iterator = nowPlayingMediaSet.entrySet().iterator();
            // set images on now playing
            for (int i = 0; i < btnImgNowPlaying.length && iterator.hasNext(); ++i) {
                Map.Entry mEntry = (Map.Entry) iterator.next();
                Show mShowNowPlaying = (Show) mEntry.getKey();
                // get show status
                currentProgressBarIndex = i;
                mProgressStatus[i] = ScheduleManager
                        .getCurrentPlayingShowStatus(mShowNowPlaying);
                // Update the progress bar
                publishProgress(mProgressStatus[i]);
            }
            // sleep 20 second to show the progress
            try {
                Thread.sleep(20000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        return null;
    }

    @Override
    protected void onPostExecute(Integer result) {
        // TODO Auto-generated method stub
        super.onPostExecute(result);
    }

    @Override
    protected void onProgressUpdate(Integer... progress) {
        // TODO Auto-generated method stub
        this.progBar[currentProgressBarIndex].setProgress(progress[0]);
    }

发生的事情是,只更新数组中的最后一个progressbar。休息时间更新,但后来......我确信我在这里做错了..

0 个答案:

没有答案