当我使用findViewHolderForAdapterPosition(postion)时,RecyclerView复制adapterPostion

时间:2017-03-11 07:53:27

标签: android android-recyclerview progress-bar

我正在尝试使用findViewHolderForAdapterPosition(postion)基于AdapterPostion在RecyclerView上设置进度条。但是在滚动Recyclerview时它会被重复,任何人都可以告诉我如何解决这个问题。

我通过以下代码获取视图

private RecyclerView.ViewHolder findViewForAsset(String id){
    int i = 0;
    for(Entity image: imagesList){
        i++;
        if(asset.getId().equals(id)){
            break;
        }
    }

    return mRecyclerView.findViewHolderForAdapterPosition(i);
}

我正在通过以下方式更新进度:

public void updateProgressView(String id,boolean isDownloading){
    RecyclerView.ViewHolder assetView = findViewForAsset(id);
    if (assetView == null) {
        return;
    }
    final ProgressBar progressBar = (ProgressBar) assetView.itemView.findViewById(R.id.asset_download_progress);
    final ImageView downloadMask = (ImageView) assetView.itemView.findViewById(R.id.download_mask);
    final ImageView assetimage = (ImageView) assetView.itemView.findViewById(R.id.iv_asset_image);

    if(isDownloading){
        progressBar.setProgress(0);
        progressBar.setVisibility(View.VISIBLE);
        downloadMask.setVisibility(View.VISIBLE);
    }else {
        runOnUiThread(  new Runnable() {
            @Override
            public void run() {
                progressBar.setProgress(0);
                progressBar.setVisibility(View.GONE);
                downloadMask.setVisibility(View.GONE);
            }
        });
    }
}

0 个答案:

没有答案