I'm using TouchImageView to load images in full screen and have zoom/pinch capability.
The images are pulled from URL via a web service. The response is in JSON. At this part, I'm using Volley+GSON to obtain the response and use a custom adapter to populate the Pager.
Initially, the images are shown in a listview. When a user click an item, it will go full screen showing the chosen item.
However, in my case, this doesn't happen. Whatever position the user chose, it will still show the image at index 0.
Here is how I do it:
In this adapter, a user will click an item and it will pass the position to another activity.
public class ItemPhotoAdapter extends BaseAdapter {
private ArrayList<ItemImageModel> arrItemImage;
@Override
public ItemImageModel getItem(int i) {
return arrItemImage.get(i);
}
...
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
ViewHolder vh;
lf = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if(view == null){
vh = new ViewHolder();
view = lf.inflate(R.layout.row_photo_grid, null);
vh.item_image = (ImageView) view.findViewById(R.id.img_item);
view.setTag(vh);
} else {
vh = (ViewHolder) view.getTag();
}
ItemImageModel iim = arrItemImage.get(i);
Picasso.with(context) //
.load(iim.getResized()) //
.placeholder(R.drawable.placeholder) //
.error(R.drawable.error)
.into(vh.item_image);
vh.item_image.setOnClickListener(new OnImageClickListener(i));
return view;
}
...
private class OnImageClickListener implements View.OnClickListener {
int _position;
public OnImageClickListener(int position) {
this._position = position;
}
@Override
public void onClick(View view) {
Intent i = new Intent(context, PhotoGalleryActivity.class);
i.putExtra("position", _position);
context.startActivity(i);
}
}
}
In PhotoGalleryActivity
, will load all the images back, but it doesn't start with the item the user chose.
public class PhotoGalleryActivity extends FragmentActivity {
private ArrayList<ItemImageModel> arrItemImages;
...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_photo_gallery);
ViewPager mViewPager = (ViewPager) findViewById(R.id.pager);
pb = (ProgressBar) findViewById(R.id.loading);
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
arrItemImages = new ArrayList<ItemImageModel>();
Intent i = getIntent();
final int position = i.getIntExtra("position", 1);
user_id = i.getStringExtra("user_id");
item_id = i.getStringExtra("item_id");
// Log.d(TAG, "Image position: " + position);
mAdapter = new PhotoGalleryAdapter(arrItemImages, getApplicationContext(), this);
mViewPager.setAdapter(mAdapter);
mViewPager.setCurrentItem(position);
// ViewPagerIndicator
CirclePageIndicator titleIndicator = (CirclePageIndicator)findViewById(R.id.titles);
titleIndicator.setViewPager(mViewPager);
loadPhotos();
}
...
private void loadPhotos() {
mRequestQueue = Volley.newRequestQueue(this);
String url = Constants.ITEM_DETAILS;
GsonRequest<ItemDetailContainer> myReq = new GsonRequest<ItemDetailContainer>(
Request.Method.GET, url, ItemDetailContainer.class,
createMyReqSuccessListener(), createMyReqErrorListener());
mRequestQueue.add(myReq);
}
...
}