Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8858391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:49:06+00:00 2026-06-14T14:49:06+00:00

I have 3 fragments in my activity, managed by a custom class which extends

  • 0

I have 3 fragments in my activity, managed by a custom class which extends FragmentPagerAdapter.

My Main xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
      >

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
          />

        <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
          />

        <Button
            android:id="@+id/button3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
          />


  <android.support.v4.view.ViewPager
                android:id="@+id/tabviewpager"
                android:layout_width="fill_parent"
                android:layout_height="0dp"
                android:layout_weight="1" />

</LinearLayout>

My activity :

public class RankingFragmentActivity extends FragmentActivity{
....

  List fragments = new Vector();


fragments.add(Fragment.instantiate(this,Tab1Fragment.class.getName()));
fragments.add(Fragment.instantiate(this,Tab2Fragment.class.getName()));
fragments.add(Fragment.instantiate(this,Tab3Fragment.class.getName()));

//adapter
MyPagerAdapter mPagerAdapter =  new MyPagerAdapter(super.getSupportFragmentManager(), fragments);

ViewPager pager = (ViewPager) super.findViewById(R.id.tabviewpager);

pager.setAdapter(this.mPagerAdapter);

}

I can perfectly switch from fragments from letf to right (and right to left).

I ‘d like to set buttons as listeners (in order to change displayed fragment) but I don’t know how to do.

ex:
click on button1 : Fragment 1 is displayed

click on button2 : Fragment 2 is displayed

click on button3 : Fragment 3 is displayed

Thank you !

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T14:49:07+00:00Added an answer on June 14, 2026 at 2:49 pm

    The answer is right in the documentation for FragmentPagerAdapter

        // Watch for button clicks.
        Button button = (Button)findViewById(R.id.goto_first);
        button.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                mPager.setCurrentItem(0);
            }
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using fragments to show images/pages.I have one Activity(Main) which contains all the
I have a App with several Fragments which are managed by one Activity. My
I have an activity with 2 fragments. I have added custom animations for fragment
I have 3 fragments that are managed by an FragmentPagerAdapter, set to a viewPager.
I have an Activity that loads 2 fragments in its XML file, these two
can i use fragments and map view in the same activity. I have seen
I've just started converting my apps to use fragments. I have a ListView activity
I have an Activity which uses a Fragment . I simply want to pass
I have a very simple activity just to show the preference fragment: public class
I have some fragments in my activity [1], [2], [3], [4], [5], [6] And

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.