BottomNavigation icon indicating copy to clipboard operation
BottomNavigation copied to clipboard

What is the purpose of using addOnPageChangeListener?

Open badarshahzad opened this issue 6 years ago • 1 comments

Hi, Firstly, thank you to teach us android. We realize how much effort to put to create repo, atricale and such post. Honestly, salute you for your job :+1: :100:

Well I want your response on this your below code mention code from this site . The example is working perfectly but what I have view that the below use is useless ? Why are you again attaching pageChangeListener ?

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

            }

            @Override
            public void onPageSelected(int position) {
                if (prevMenuItem != null) {
                    prevMenuItem.setChecked(false);
                }
                else
                {
                    bottomNavigationView.getMenu().getItem(0).setChecked(false);
                }
                Log.d("page", "onPageSelected: "+position);
                bottomNavigationView.getMenu().getItem(position).setChecked(true);
                prevMenuItem = bottomNavigationView.getMenu().getItem(position);

            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

badarshahzad avatar Dec 19 '17 06:12 badarshahzad

Well what I have concluded against this if you want menu enabled with swap of viewpage then we have to do this

  @Override
            public void onPageSelected(int position) {
                bottomNavg.getMenu().getItem(position).setChecked(true);
            }

badarshahzad avatar Dec 19 '17 06:12 badarshahzad