IntentService:使用广播意图更新列表项中的进度条

问题描述

我有一个ListView包含3个列表项,每个项目中都有进度条 单击的每个列表项都将启动一个 Intent Service ,该服务会下载文件并在进度栏中显示进度。下面是我的代码

@Override
    protected void onHandleIntent(Intent intent) {

       int progress = (int) ((total * 100) / fileSize);
            
       Download download = new Download();
       download.setProgress(progress );

}

  private void sendIntent(Download download){

        Intent intent = new Intent(ManageContentActivity.MESSAGE_PROGRESS);
        intent.putExtra("download",download);
        LocalbroadcastManager.getInstance(DownloadService.this).sendbroadcast(intent);
    }

在我的活动中,我正在使用broadcastReciever更新我的列表视图项

 private broadcastReceiver broadcastReceiver = new broadcastReceiver() {
        @Override
        public void onReceive(Context context,Intent intent) {

            if(intent.getAction().equals(MESSAGE_PROGRESS)){

                Download download = intent.getParcelableExtra("download");


                View view = itemsListView.getChildAt(download.getItem_index());
                if (view != null) {
                    progressBar = view.findViewById(R.id.tv);
                    if (progressBar != null) {
                        progressBar.setProgress(download.getProgress(),true);
                        Log.d("Progress",""+download.getProgress());
                    }
                }

            }
        }
    };

在尝试显示第二个列表项的进度时,我在这里遇到问题。它达到96%,然后更新了第一个列表项的进度条。我不确定这里发生了什么。任何帮助将不胜感激。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...