I’m using the nostra13 UniversalImageLoader to load a bunch of images into a gridview and its working beautifully, but when a user clicks an item on my menu, i need the images to change (not open a new page, but reload/refresh the images on the same page)
I’m calling the imageloader like so:
protected ImageLoader imageLoader;
imageLoader = ImageLoader.getInstance();
imageLoader.init(ImageLoaderConfiguration.createDefault(this));
Bundle bundle = getIntent().getExtras();
imageUrls = bundle.getStringArray(Extra.IMAGES);
options = new DisplayImageOptions.Builder()
.showStubImage(R.drawable.stub_image)
.showImageForEmptyUri(R.drawable.image_for_empty_url)
.cacheInMemory()
.cacheOnDisc()
.bitmapConfig(Bitmap.Config.RGB_565)
.build();
final GridView main_gridview = (GridView)findViewById(R.id.main_gridview);
main_gridview.setAdapter(new ImageAdapter());
public class ImageAdapter extends BaseAdapter {
@Override
public int getCount() {
return imageUrls.length;
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final ImageView imageView;
if (convertView == null) {
imageView = (ImageView) getLayoutInflater().inflate(R.layout.item_grid_image, parent, false);
} else {
imageView = (ImageView) convertView;
}
imageLoader.displayImage(imageUrls[position], imageView, options);
return imageView;
}
}
So as you can see the Extras.IMAGES is the string array containing the various URLs, so when a user clicks said button on the menu, I have the array containing the new URLS, but am not sure how to ‘refresh’ the image adapter?
I understand you can ‘add’ pictures to the gridview on the fly, but I didnt see in nostra’s documentation if you could completely refresh the whole array..
Any help is greatly appreciated. 🙂
PS. Sorry if the answer to this is obvious I’m only about a week into android dev.
I solved it. Just set ImageUrls to my string array of updated images, then I declared the ImageAdapter object at the top and called notifyDataSetChanged() on that object like so: