I have a ViewPager wrapped inside a SwipeRefreshLayout. Sometimes, when I swipe to the left/right the SRL get's triggered. This mostly happens when I'm at the top of my fragment.
How do I solve this? Do I need to listen to some kind of event in order to disable the SRL during a certain time? I haven't really found anything about it so I doubt this is an actual bug by Google but rather am I implementing something incorrectly? Any ideas on this?
That's my layout:
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/mainSwipeContainer"
android:layout_width="wrap_content"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
android:id="@+id/mainViewPager"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</android.support.v4.widget.SwipeRefreshLayout>
Thanks! Let me know if I'm missing out any information.
I managed to solve it:
mainViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(mainTabLayout) {
@Override
public void onPageScrollStateChanged(int state) {
toggleRefreshing(state == ViewPager.SCROLL_STATE_IDLE);
}
});
your toggleRefreshing() should then look something like this:
public void toggleRefreshing(boolean enabled) {
if (swipeRefreshLayout != null) {
swipeRefreshLayout.setEnabled(enabled);
}
}