InfiniteViewPager
InfiniteViewPager copied to clipboard
Hiding Button as a function of position
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) {
}
});
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