Take position of the arraylist that is in focus in Viewpager

Asked

Viewed 555 times

0

I have an arraylist of images that is shown in a Viewpager, so far so good, this showing all the arraylist normally.

But how do I get the Viewpager that’s in focus? That is to take the right position of the arraylist being viewed by Viewpager

private class ImagePagerAdapter extends PagerAdapter {

        private ArrayList<Galeria> images;
        private LayoutInflater inflater;

        ImagePagerAdapter(ArrayList<Galeria> images) {
            this.images = images;
            inflater = getLayoutInflater();
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View) object);
        }

        @Override
        public int getCount() {
            return images.size();
        }

        @Override
        public Object instantiateItem(ViewGroup view, final int position) {
            View imageLayout = inflater.inflate(R.layout.item_pager_image, view, false);
            assert imageLayout != null;
            ImageView imageView = (ImageView) imageLayout.findViewById(R.id.image);
            final ProgressBar spinner = (ProgressBar) imageLayout.findViewById(R.id.loading);
            Log.i("POSITION",""+position);

... o resto do código não importa

1 answer

1


To get the position that is being displayed, just use the method ViewPager.getCurrentItem(), it provides the position for the item being displayed from PagerAdapter at the moment.

To access the image, simply access the instance of PagerAdapter, either by a local variable of your Activity or using the ViewPager.getAdapter.

  • stupid of mine.. I was looking for this on the Adapter

Browser other questions tagged

You are not signed in. Login or sign up in order to post.