I have set up a View Pager and a Gallery. I would like to update my View Pager's ImageView from my gallery's OnItemClickListener and pass it the ImageView so that it will update so there will be a larger view of the image.
How would I be able to achieve this? if anyone could help me out, that would be fantastic, thanks.
Here's what I have set up(See bottom of class for onClickGallery):
public void updateUI(final SimpleItemType item) {
class ImagePagerAdapter extends PagerAdapter {
private List<String> mImages = item.pictureURL;
@Override
public int getCount() {
if (mImages == null) {
SuperToast.create(
getApplicationContext(),
"No image available",
SuperToast.Duration.VERY_SHORT,
Style.getStyle(Style.GRAY,
SuperToast.Animations.SCALE)).show();
}
else {
return mImages.size();
}
return 0;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == ((ImageView) object);
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
Context context = DetailActivity.this;
ImageView imageView = new ImageView(context);
int padding = context.getResources().getDimensionPixelSize(
R.dimen.padding_medium);
imageView.setPadding(padding, padding, padding, padding);
imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
Picasso.with(context).load(item.pictureURL.get(position)).fit()
.centerInside().into(imageView);
((ViewPager) container).addView(imageView);
return imageView;
}
@Override
public void destroyItem(ViewGroup container, int position,
Object object) {
((ViewPager) container).removeView((ImageView) object);
}
}
class ImageGalleryAdapter extends BaseAdapter {
private List<String> mImages = item.pictureURL;
@Override
public int getCount() {
return mImages.size();
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView = (ImageView) convertView;
Context context = DetailActivity.this;
if (imageView == null) {
imageView = (ImageView) getLayoutInflater().inflate(
R.layout.item_gallery_image, parent, false);
}
Picasso.with(context).load(item.pictureURL.get(position)).fit()
.centerInside().into(imageView);
return imageView;
}
}
gallery.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
//Here I would like to pass my ImageView from gallery to view pager
}
});
Try declaring the viewpager's imageview global (like mImages), and then to change the imageview's image like this:
imageView.setBackgroundResource(your.image.resource);