简体   繁体   中英

android with viewpager When i click on Button in the first fragment I want the app to navigate to another activity

I have two fragments implemented using View Pager. In fragment 1 I have 2 button and in fragment 2 I have list of item.

When I click on particular button in the first fragment I want the app to navigate to another activity.

but this scenario when I click on particular button in the first fragment then It's click on Second fragment list item and open list item detail.

If anybody knows, please suggest me a solution. I need to do this as soon as possible.

Thanks

One thing that came on top of my head is this:

  1. Store your fragments in a ViewPager.
  2. Listen to button click events in your first fragment.
  3. From your first fragment, notify your activity of said click event.
  4. Your activity (which also houses the ViewPager) should respond to the click event by commanding the ViewPager to move to the second page (which also contains your second fragment). You can do this by calling yourViewPager.setCurrentItem() .

And there you have it. A fragment that contains button which move the pager onto the next page/fragment.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM