I didn't find an answer here, here and here.
I have an activity that shows list of posts (with or without images). When I scroll down and scroll up or refresh the list using SwipeRefreshLayout
some of the images may disapper. I use RecyclerView
to show list of posts and Picasso
to load images. Here is my adapter binding:
@Override
public void onBindViewHolder(ItemViewHolder holder, int position) {
// <...>
if (item.getPhoto() != null) {
Picasso.with(context)
.load(item.getPhoto())
.into(holder.mPostPhoto);
} else {
holder.mPostPhoto.setImageDrawable(null);
holder.mPostPhoto.setVisibility(View.GONE);
}
}
I send HTTP request to get posts and when I have new data I call PostsAdapter
:
public void addAll(List<PostResponse> items) {
this.items.clear();
this.items.addAll(items);
notifyDataSetChanged();
}
In MainActivity:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// <...>
mPostAdapter = new PostAdapter();
mPosts.setLayoutManager(new LinearLayoutManager(MainActivity.this));
mPosts.setAdapter(mPostAdapter);
mPostsSwipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
updatePosts();
}
});
updatePosts();
}
private void updatePosts() {
new Api(this).getPosts(new GetPostsCallback(this) {
@Override
public void onSuccess(final Paging<PostResponse> paging) {
runOnUiThread(new Runnable() {
@Override
public void run() {
mPostAdapter.addAll(paging.getData());
mPostsSwipeRefresh.setRefreshing(false);
}
});
}
});
}
I find it's pretty basic, I don't understand why images disappear time after time. My list is not long and images resized before the upload to the server, they shouldn't use much memory. And the worst, when they disappear, they don't reload. They may reload only after I scroll down and up...
- Please explain me why it happens.
- How can I fix this problem?
Thanks!