setOnPageChangeListener

setOnPageChangeListener

This question already has answers here:
viewpager setonpagechangelistener deprecated
                                
                                    (5个答案)
                                
                        
                                3年前关闭。
            
                    
我正在使用Android Studio开发针对API级别22的应用程序,而使用compileSdkVersion级别是23。
当我尝试在以下代码中实现ViewPager.OnPageChangeListener()时,它给出了


  不推荐使用setOnPageChangeListener。


 viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {}


我想对viewPager.setOnPageChangeListener()进行的操作是:

viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageSelected(int position) {
            txtPropertyOverviewImageCount.setText(position + "/" + GalleryImages.length);
            //GalleryImage have no of item is same size of viewpager
            //i want O/P like this
            // 1/8
            // 2/8
            // 3/8
            LogUtils.Log_e("CurrentPage", position + "");
        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });

最佳答案

是的,不赞成使用setOnPageChangeListener,而推荐使用addOnPageChangeListener,以便在需要时可以注册多个侦听器。您可以找到文档here

07-26 09:31