Please tell me what I'm doing wrong. I have a GridView, which the grid displays images from resources. I store them in an array in the main activation like this:
public static int[] mThumbIds = { R.drawable.card1, R.drawable.card2, R.drawable.card3, R.drawable.card4, R.drawable.card5, R.drawable.card6, R.drawable.card7, R.drawable.card8, R.drawable.card9, R.drawable.card10, R.drawable.card11, R.drawable.card12, R.drawable.card13, R.drawable.card14, R.drawable.card15, R.drawable.card16, R.drawable.card17, R.drawable.card18, R.drawable.card19, R.drawable.card20, R.drawable.card21 }; By clicking on the image, I get its number in the array (the number is correct, I checked it with logs), I insert this number into Intent and open a new activation:
Intent i = new Intent(getApplicationContext(), FullImageActivity.class); // passing array index i.putExtra("id", position); startActivity(i); In the new asset, I get the number, initialize the ViewPager, point the adapter to it and pass this same position to one of the parameters:
viewPager = (ViewPager) findViewById(R.id.myViewPager); adapter = new SlideImageAdapter(this, position); viewPager.setAdapter(adapter); Further, the problem itself: In the adapter, I get the desired position, when I click on the image, the correct image is displayed, but when I swipe left and right, the image does not change. If I try to get an image directly from the adapter, then by clicking on any image the first one in the array is always displayed, although in this case the svaping works correctly. How to properly implement my idea? Here is the adapter itself:
public class SlideImageAdapter extends PagerAdapter { private Context mContext; private LayoutInflater layoutInflater; int number; public SlideImageAdapter(Context mContext, int number){ this.mContext = mContext; this.number = number; } @Override public int getCount() { return MainActivity.mThumbIds.length; } @Override public boolean isViewFromObject(View view, Object object) { return (view==(LinearLayout)object); } @Override public Object instantiateItem(ViewGroup container, int position) { layoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View item_view = layoutInflater.inflate(R.layout.swipe_layout, container, false); ImageView imageView = (ImageView) item_view.findViewById(R.id.full_image_view); imageView.setImageResource(MainActivity.mThumbIds[position]); container.addView(item_view); return item_view; } @Override public void destroyItem(ViewGroup container, int position, Object object) { container.removeView((LinearLayout)object); } }