Reputation: 162
I have problem with Picasso cache (I think so). I created RecyclerView and RecyclerView.Adapter. A single item on the list contain ImageView. To this imageView I load image using Picasso library like this:
public void onBindViewHolder(PageViewHolder holder, int position) {
final int positionAdp = holder.getAdapterPosition();
(new Picasso.Builder(mContext).addRequestHandler(new PageThumbRequestHandler(mPagesContainer.get()))
.build())
.load(PageThumbRequestHandler.REQUEST_SCHEME + "://" + mPages.get(positionAdp).mTag)
.memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE)
.networkPolicy(NetworkPolicy.NO_CACHE)
.into(holder.mThumbView);
holder.mThumbView.setTag(mPages.get(positionAdp).mTag);
holder.mThumbView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String tag = (String) v.getTag();
mPageListener.onPageSelected(tag);
}
});
holder.mLp.setText(Integer.toString(mPages.get(positionAdp).mLp));
}
When I update item I call notifyItemChanged method. On screen I see that updated item is flicking, so item is invalidate correctly. But new thumb is not display - i always get first loaded bitmap into ImageView.
Upvotes: 0
Views: 546
Reputation: 1772
You should not use the holder.getAdapterPosition()
for this, as the RecyclerView JavaDoc states:
[...] you should only use the position parameter while acquiring the related data item inside this method and should not keep a copy of it. If you need the position of an item later on (e.g. in a click listener), use getAdapterPosition() which will have the updated adapter position.
So, do not use the getAdapterPosition()
unless you are sure it will be executed asynchronously by unknown factors, such as user interaction (ie. inside a click or touch listener).
For the first load of the View Holder, use the position
argument from the onBindViewHolder(ViewHolder holder, int position)
method, that will be the position of the data in the recycler's Adapter.
Upvotes: 0