How To Manage Multiple Download With Firebase And RecyclerView
Solution 1:
Like mentioned in the comments this request shouldn't be done in the RecyclerView.Adapter
, and should definitely not be made in the onBindViewHolder
.
You should abstract this to a separate class, a Presenter
or the framework's own ViewModel
, that being said:
Once that request is made and the new data comes in, you should update your adapter's data model
and notify of these changes.
Reporting a click (that would eventually trigger a request) should be done via an interface where you could have your Adapter
:
public interface Listener {
void onItemClicked(YourModelPojo item);
}
And your Activity/Fragment/Presenter however abstract you want to do would implement this Listener interface.
So your adapter's
holder.imgDocumentChecker.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
// Update the UI the request is being made and report to listener
listener.onItemClicked(data.get(getAdapterPosition()));
}
Then your adapter should also have an update item on the adapter's data and notify of this change. Since your model changed your bindViewHolder
would update the UI correctly.
Of course, you have to implement these UI changes (data downloading/updated/etc.)
I've written some articles that you can rely on (with open source code):
Post a Comment for "How To Manage Multiple Download With Firebase And RecyclerView"