Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is the purpose of using addOnPageChangeListener? #2

Open
badarshahzad opened this issue Dec 19, 2017 · 1 comment
Open

What is the purpose of using addOnPageChangeListener? #2

badarshahzad opened this issue Dec 19, 2017 · 1 comment

Comments

@badarshahzad
Copy link

badarshahzad commented Dec 19, 2017

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 👍 💯

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
Copy link
Author

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);
            }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant