-
Notifications
You must be signed in to change notification settings - Fork 193
Description
I've got a strange bug, when i use the InfiniteViewPager in my code. If i change the direction of page scrolling it skips 2 fragments. For istance if i'm at page 5 and i've been scrolling right, than if i scroll right i'll go to page 6. If i scroll left i'll go at page 2, skipping the 2 pages in the middle.
Here is the MainActivity:
`
public class MainActivity extends AppCompatActivity {
@OverRide
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.navigation_drawer_layout);
//InfinitePageViewer Implementation
PagerAdapter adapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
@Override
public int getCount() {
return 1000;
}
@Override
public MyFragment getItem(int position) {
int index;
if(position < 500)
index = position;
else
index = position - 1000; // 999->-1 998->-2
Bundle bundle = new Bundle();
MyFragment fragment = new MyFragment();
bundle.putStringArrayList("GoalList", mDay.getGoalList());
bundle.putLong("Page", index);
fragment.setArguments(bundle);
return fragment;
}
};
// wrap pager to provide infinite paging with wrap-around
PagerAdapter wrappedAdapter = new InfinitePagerAdapter(adapter);
// actually an InfiniteViewPager
ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
viewPager.setAdapter(wrappedAdapter);
}
//Set the date on the Toolbar
Toolbar toolbar = (Toolbar)findViewById(R.id.my_awesome_toolbar);
toolbar.setTitle("My title");
setSupportActionBar(toolbar);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
toggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close);
toggle.setDrawerIndicatorEnabled(true);
mDrawerLayout.setDrawerListener(toggle);
setupDrawerUI();
}
`
Here is the navigation_drawer_layout.xml:
`
<android.support.v7.widget.Toolbar
android:id="@+id/my_awesome_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/grey_900"
app:titleTextColor="@color/grey_white_1000"
app:subtitleTextColor="@color/grey_white_1000"
app:collapseIcon="@color/grey_white_1000"
android:navigationIcon="@color/grey_white_1000"
android:collapseContentDescription="@color/grey_white_1000"
android:minHeight="?attr/actionBarSize" />
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.antonyt.infiniteviewpager.InfiniteViewPager
android:id="@+id/pager"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<!-- The navigation drawer -->
<LinearLayout
android:id="@+id/navigation_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/grey_white_1000"
android:orientation="vertical" >
<Button
android:id="@+id/secondButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="@drawable/listview_selector"
android:gravity="center"
android:text="Show Odd Numbers"
android:textColor="@color/primary" />
<Button
android:id="@+id/firstButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="@drawable/listview_selector"
android:gravity="center"
android:text="Show Even Number"
android:textColor="@color/primary" />
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
`
On the fragment i have a RecyclerView, can it be him the cause?