この後、Viewpager 内に TouchImageView を正常に作成しました>>
private class ImagePagerAdapter extends PagerAdapter {
@Override
public int getCount() {
return image_name_array.size();
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == ((TouchImageView) object);
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
Context context = getActivity().getApplicationContext();
// define Image View
TouchImageView imageView = new TouchImageView(context);
imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
int padding = context.getResources().getDimensionPixelSize(R.dimen.padding_medium);
imageView.setPadding(padding, padding, padding, padding);
try {
// draw image using bitmap
Bitmap image_drawable = BitmapFactory.decodeStream(getActivity().getAssets().open(image_name_array.get(position)));
imageView.setImageDrawable(new BitmapDrawable(getActivity().getResources(), image_drawable));
} catch (Exception e) {
e.printStackTrace();
}
// imageView.setImageResource(mImages[position]);
((ViewPager) container).addView(imageView, 0);
return imageView;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
((ViewPager) container).removeView((ImageView) object);
}
}
私はinstantiateItemメソッドで次のように変更しました:
public Object instantiateItem(ViewGroup container, int position) {
TouchImageView imageDisplay;
TextView description;
inflater = (LayoutInflater) container.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.details_images_caption, container, false);
imageDisplay = (TouchImageView) view.findViewById(R.id.gallery_image);
description = (TextView) view.findViewById(R.id.gallery_description);
//Log.e("image aptadapter =>", image_caption.get(position).toString());
description.setText(image_caption.get(position));
String picture = image_name_array.get(position);
Log.e("image DataADA =>", picture);
if (!TextUtils.isEmpty(picture)) {
try {
Bitmap image_drawable = BitmapFactory.decodeStream(context.getAssets().open(picture));
imageDisplay.setImageDrawable(new BitmapDrawable(context.getResources(), image_drawable));
} catch (Exception e) {
}
}
return view;
}