In Android Studio I want to have a different tab every time I swipe left/right. So I want to make information on a 'page' change when I swipe left/right, with the animation of moving in that direction. I do not know how to use fragments.
Asked
Active
Viewed 34 times
-1
-
Possible duplicate of [How to update the List whenever the tabs are changing in view pager](https://stackoverflow.com/questions/30231180/how-to-update-the-list-whenever-the-tabs-are-changing-in-view-pager) – InsaneCat Dec 12 '17 at 05:14
2 Answers
0
you want to get position of fragments if it swap so you need to add page change listener.
viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
// it returns position
//do there your code according position
}
@Override
public void onPageScrollStateChanged(int state) {
}
});

Mayank Garg
- 1,284
- 1
- 11
- 23
0
I think youre looking for this one View Pager with Fragments and Creating Swipe Views with Tabs Docs Tutorials for ActionBar Tabs with Fragments.

Benjith Mathew
- 1,211
- 1
- 11
- 23
-
Don't put comments in answer post. gave description of your answer otherwise post in comments. – InsaneCat Dec 12 '17 at 05:10