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

Hiding Button as a function of position #38

Open
SeloSlav opened this issue Nov 24, 2015 · 1 comment
Open

Hiding Button as a function of position #38

SeloSlav opened this issue Nov 24, 2015 · 1 comment

Comments

@SeloSlav
Copy link

The following code sets up my InfiniteViewPager and hides a button depending on the position of the pager. It works, as in the buttons starts GONE, and appears when you swipe to a new position, but as you swipe back to "position 0" the button reappears. I believe this is because when I swipe back, the position is no longer really "position 0". I get the following in my logcat when I return to the image contained in "position 0":

11-23 23:29:49.694  25109-25109/com.app.store D/InfinitePagerAdapter﹕ instantiateItem: real position: 3301
11-23 23:29:49.694  25109-25109/com.app.store D/InfinitePagerAdapter﹕ instantiateItem: virtual position: 1

This is the code for initiating my pager and the OnPageChangeListener.

private void init(Context context) {
    View view = inflate(context, R.layout.listview_item, this);
    view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));

    ViewPager viewPager;
    CustomPagerAdapter adapter;
    viewPager = (ViewPager) findViewById(R.id.view_pager);
    adapter = new CustomPagerAdapter(context);

    PagerAdapter wrappedAdapter = new InfinitePagerAdapter(adapter);
    viewPager.setAdapter(wrappedAdapter);

    //Hide the button unless showing image
    final Button selectButton = (Button) findViewById(R.id.selectButton);
    selectButton.setVisibility(GONE);

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

        }

        @Override
        public void onPageSelected(int position) {
             if(position==0)
                selectButton.setVisibility(View.GONE);
             else
                selectButton.setVisibility(View.VISIBLE);
        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });
@adamhongmy
Copy link

I'm having this issue too! I want to show the indicators based onPageSelected position but it is 300. Seeing this post was posted 2 years ago, well, I'm screwed T.T

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

2 participants