【问题标题】:Update Selected Progressbar in RecyclerView更新 RecyclerView 中的选定进度条
【发布时间】:2018-09-10 10:36:41
【问题描述】:

我有一个自定义适配器,其中包含一些 TextViewsProgressBars。当用户单击每一行时,我想显示所选行的ProgressBar 并更新值。这是我的适配器:

 public class MyViewHolder extends RecyclerView.ViewHolder implements View.OnLongClickListener {
        public TextView from, subject;
        public ProgressBar progressBar;
  public MyViewHolder(View view) {
            super(view);
            from = (TextView) view.findViewById(R.id.from);
            subject = (TextView) view.findViewById(R.id.txt_primary);
            progressBar = (ProgressBar) view.findViewById(R.id.progressBar);
            view.setOnLongClickListener(this);
        }
}

这是我在 MainActivity 中的点击事件

 @Override
    public void onMessageRowClicked(int position) {
        if (mAdapter.getSelectedItemCount() > 0) {
            enableActionMode(position);

        } else {
                message = messages.get(position);
                message.setRead(true);
                messages.set(position, message);
                mAdapter.notifyDataSetChanged();
               downloadFile(message.getFrom(), getBaseUrl() + message.getLink());
        }
    }

这是我的下载文件

 private void downloadFile(final String filename, final String path){

                    int downloadId = PRDownloader.download(path, dPath, mylFileName)
                            .build()
                            .setOnProgressListener(new OnProgressListener() {
                                @Override
                                public void onProgress(Progress progress) {

                                }
                            })
                            .start(new OnDownloadListener() {
                                @Override
                                public void onDownloadComplete() {

                                    }
                                }

                                @Override
                                public void onError(Error error) {

                                }
                            });
                }
            }).execute(path);
        }
    }

我是初学者,我不知道该怎么做。

【问题讨论】:

    标签: android android-recyclerview custom-adapter


    【解决方案1】:

    使用它在 onMessageRowClicked() 方法中显示 ProgressBar 的值

     progressBar.setProgress(value);//value will be of Integer type
    

    这样,

     .setOnProgressListener(new OnProgressListener() {
                            @Override
                            public void onProgress(Progress progress) {
                                long progressPercent = progress.currentBytes * 100 / progress.totalBytes;
                                progressBar.setProgress((int) progressPercent);
                                progressBar.setIndeterminate(false);
                            }
                        })
    

    【讨论】:

    • 问题是我找不到进度条(每一行都有自己的进度条)
    • 您不必明确地找到位置,因为您可以看到该方法本身在您单击一行时传递进度条的位置。即 onMessageRowClicked(int position)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-08
    • 2020-11-05
    • 2015-01-24
    • 1970-01-01
    • 2014-04-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多