Pick arraylist position that is in focus in ViewPager

0

I have an arraylist of images that is displayed in a ViewPager, so far so good, it's showing the whole arraylist normally.

But how do I get the ViewPager that is in focus? In other words, to get the right position of the arraylist being viewed by the 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
    
asked by anonymous 29.09.2014 / 00:40

1 answer

1

To get the position being displayed, simply use the ViewPager.getCurrentItem() ", it provides the position for the item currently being displayed for PagerAdapter .

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

    
29.09.2014 / 00:45