Android 更新asynctask中progressbar的数组

Android 更新asynctask中progressbar的数组,android,android-asynctask,android-progressbar,Android,Android Asynctask,Android Progressbar,我有一个asynctask,其中我传递了一个progressbar数组作为参数。在doinbackground方法中,我计算每个progressbar的进度,并以进度作为参数调用PublishProgress。我就是这样做的: static volatile int currentProgressBarIndex; @Override protected Integer doInBackground(String... arg0) { // TODO Auto-gene

我有一个
asynctask
,其中我传递了一个
progressbar数组作为参数。在
doinbackground
方法中,我计算每个progressbar的进度,并以进度作为参数调用
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]);
    }
静态易失性int-currentProgressBarIndex;
@凌驾
受保护的整数doInBackground(字符串…arg0){
//TODO自动生成的方法存根
//显示正在播放的图像
while(ScheduleManager.isScheduleRunning){
迭代器迭代器=nowPlayingMediaSet.entrySet().Iterator();
//设置正在播放的图像
对于(int i=0;i

发生的情况是,仅更新数组中最后一个
progressbar
。Rest会更新,但稍后会更新。。我肯定我在这里做错了什么

为什么是Barindex?只需生成一个进度列表并将其传递给publishProgress即可。在onProgressUpdate中,迭代列表并将int值分配给相应的进度条。不需要currentProgressBarIndex.Wow。。那很简单!它现在运转良好。。