RecyclerView Getting Unique Reference to a ViewHolder


Please briefly explain why you feel this question should be reported .

Report Cancel

In my recyclerview.viewholder’s onBindView method, I bind an OnClickListener to a button inside the ViewHolder. The operation associated with the Click is supposed to be long and asynchronous, so I create and assign a new custom Callback method named DownloadCallback.

DownloadManager.getInstance().download(request, fileinfo.getTag(), new DownloadCallback(position, fileinfo));

As you can see, the Callback needs a reference to the ViewHolder in order to update the progress status so I pass it the current ViewHolder position. This works well. But as I add a new item at index 0 – and push the rest of the items down, the Callback method doesn’t know and keeps updating ViewHolders at the wrong position!

Is there a way I can come up with a unique ViewHolder reference that I can pass to the Callback? What is recyclerView.getItemId() ?

0 Answer 10 views 0