Reputation: 43
So I've checked the size of "parsedPhotoStrings" and it's clearly greater than 1. However, only one image is displayed with the following code. I'm not sure what is going on.
for (int i = 0; i < parsedPhotoStrings.size(); i++) {
String photoUrl = createPlacePhotosUrl(parsedPhotoStrings.get(i));
ImageView imageView = new ImageView(MarkerActivity.this);
Picasso.with(MarkerActivity.this).load(photoUrl).resize(width, 0).into(imageView);
photoLayout.addView(imageView);
}
EDIT:
Multiple photos are showing! I overlooked my orientation of the layout. However, the cache is still not clearing even after .netWorkPolicy(NetWorkPolicy_CLEAR_CACHE) and .memoryPolicy(MemoryPolicy.CLEAR_CACHE)
EDIT:
for (int i = 0; i < parsedPhotoStrings.size(); i++) {
String photoUrl = createPlacePhotosUrl(parsedPhotoStrings.get(i));
ImageView imageView = new ImageView(MarkerActivity.this);
photoLayout.addView(imageView);
Picasso.with(MarkerActivity.this).load(photoUrl)
.networkPolicy(NetworkPolicy.NO_CACHE, NetworkPolicy.NO_STORE)
.memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE)
.resize(width, 0)
.into(imageView);
imageView.setImageResource(0);
imageView.setImageDrawable(null);
Picasso.with(MarkerActivity.this).invalidate(photoUrl);
}
I've tried so many things to clear the cache. Still got nothing working. Any help is appreciated!
Upvotes: 0
Views: 500
Reputation: 90
It is due to caching. You have to implement this:-
Picasso.with(YourActivity.this)
.load(childjson.getString("your_string"))
.networkPolicy(NetworkPolicy.NO_CACHE)
.memoryPolicy(MemoryPolicy.NO_CACHE)
.skipMemoryCache()
.into(yourImagePreview);
And just make sure to change dependency of picasso in build.gradle with:-
compile "com.squareup.picasso:picasso:2.5.2"
This will support no memory caching. Happy Coding!
Upvotes: 0
Reputation: 4132
First check if the image is caching ht eurl,if so add the code to invalidate() the url.This wil remove previous cache.
Picasso.with(this).invalidate(url);
Second check for the network cachcing mechanism.This code will make no caching for the images
Picasso.networkPolicy(NetworkUtils.isConnected(this) ?
NetworkPolicy.NO_CACHE : NetworkPolicy.OFFLINE)
So you code should be like
for (int i = 0; i < parsedPhotoStrings.size(); i++) {
String photoUrl =createPlacePhotosUrl(parsedPhotoStrings.get(i));
Picasso.with(this).invalidate(url);
ImageView imageView = new ImageView(MarkerActivity.this);
photoLayout.addView(imageView);
Picasso.with(MarkerActivity.this)
.load(photoUrl)
.networkPolicy(NetworkUtils.isConnected(this) ?
NetworkPolicy.NO_CACHE : NetworkPolicy.OFFLINE)
.memoryPolicy(MemoryPolicy.NO_CACHE);
.resize(width, 0)
.into(imageView);
}
Also to support these code you need picasso version 2.5.+
compile 'com.squareup.picasso:picasso:2.5.2'
Upvotes: 0
Reputation: 69689
try this use .memoryPolicy(MemoryPolicy.NO_CACHE)
Picasso.with(MarkerActivity.this).load(photoUrl).resize(width, 0).memoryPolicy(MemoryPolicy.NO_CACHE).into(imageView);
sample code
for (int i = 0; i < parsedPhotoStrings.size(); i++) {
String photoUrl = createPlacePhotosUrl(parsedPhotoStrings.get(i));
ImageView imageView = new ImageView(MarkerActivity.this);
photoLayout.addView(imageView);
Picasso.with(MarkerActivity.this).load(photoUrl).resize(width, 0).memoryPolicy(MemoryPolicy.NO_CACHE).into(imageView);
}
Upvotes: 0
Reputation: 1614
Just reverse the order.
Add the ImageView
then load image:
Change this to
for (int i = 0; i < parsedPhotoStrings.size(); i++) {
String photoUrl = createPlacePhotosUrl(parsedPhotoStrings.get(i));
ImageView imageView = new ImageView(MarkerActivity.this);
Picasso.with(MarkerActivity.this).load(photoUrl).resize(width, 0).into(imageView);
photoLayout.addView(imageView);
}
This
for (int i = 0; i < parsedPhotoStrings.size(); i++) {
String photoUrl = createPlacePhotosUrl(parsedPhotoStrings.get(i));
ImageView imageView = new ImageView(MarkerActivity.this);
photoLayout.addView(imageView);
Picasso.with(MarkerActivity.this).load(photoUrl).memoryPolicy(MemoryPolicy.NO_CACHE).networkPolicy(NetworkPolicy.NO_CACHE).resize(width, 0).into(imageView);
}
Upvotes: 1