user2426316
user2426316

Reputation: 7331

How can I realize a swipe action via a button click in Android?

I am using a viewpager and two fragments. You can swipe between those fragments. Now, how can I implement a button that simulates this swipe gesture on click. Basically, I want to switch to the other fragment on a button click.

How can I do that?

Upvotes: 1

Views: 460

Answers (1)

amalBit
amalBit

Reputation: 12181

Just change the current fragment inside the onClickListner of the button you have created:

viewPager.setCurrentItem(n);

Where n is the fragment number in the FragmentPagerAdapter.

Upvotes: 1

Related Questions