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

  • SEARCH
  • Home
  • 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 8926701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:02:14+00:00 2026-06-15T08:02:14+00:00

I am struggling with the concepts needed to properly implement a view pager. By

  • 0

I am struggling with the concepts needed to properly implement a view pager. By following some tutorials and referencing developer.android.com, I am able to get a view pager almost fully functional. The pager will flip through several text views that have been setup to say “My Message 0” through “My Message 9”. The problem is that the view pager also flips the button on the bottom of the activity and the red block that is right above the button.

issues with view pager mid-flip

I would like to have the view pager only cycle through the text. Would you please help me understand what I’m doing wrong?

I have an activity that represents a dashboard:

public class DashBoard extends FragmentActivity
{
  private static final int NUMBER_OF_PAGES = 10;

  private ViewPager mViewPager;
  private MyFragmentPagerAdapter mMyFragmentPagerAdapter;

  public void onCreate(Bundle icicle){
  super.onCreate(icicle);
  setContentView(R.layout.dashboard);

  mViewPager = (ViewPager) findViewById(R.id.viewpager);
  mMyFragmentPagerAdapter = new    MyFragmentPagerAdapter(getSupportFragmentManager());
  mViewPager.setAdapter(mMyFragmentPagerAdapter);

  }

     private static class MyFragmentPagerAdapter extends FragmentPagerAdapter{
 public MyFragmentPagerAdapter(FragmentManager fm)
 {
     super(fm);
 }

 @Override
 public Fragment getItem(int index)
 {
     return PageFragment.newInstance("My Message " + index);
 }

 @Override
 public int getCount(){
     return NUMBER_OF_PAGES;
  }
  }

and a class for the page fragment:

public class PageFragment extends Fragment {

public static PageFragment newInstance(String title){

  PageFragment pageFragment = new PageFragment();
  Bundle bundle = new Bundle();
  bundle.putString("title", title);
  pageFragment.setArguments(bundle);
  return pageFragment;
    }

    @Override
    public void onCreate(Bundle icicle){
  super.onCreate(icicle);

    }

    @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle icicle){
  View view = inflater.inflate(R.layout.dashboard, container, false);
  TextView textView = (TextView) view.findViewById(R.id.textViewPage);
  textView.setText(getArguments().getString("title"));
  return view;

     }

    }

and finally, my xml for the dashboard:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/dashbaordLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>

<android.support.v4.view.ViewPager
    android:id="@+id/viewpager"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    />
<TextView
    android:id="@+id/textViewPage"
    android:layout_width = "match_parent"
    android:layout_height= "wrap_content"
    />  

<Button
    android:id="@+id/newGoalButton"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/stringNewGoal"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:onClick="createNewGoal"
    />

<RelativeLayout
    android:id="@+id/SpaceBottom"
    android:layout_width="match_parent"
    android:layout_height="75dp"
    android:layout_above="@id/newGoalButton"
    android:background="@color/red"
>

   </RelativeLayout>
     </RelativeLayout>

A note about my xml, I tried wrapping the text view in some view pager tags eg:

<android.support.v4.view.ViewPager
    android:id="@+id/viewpager"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    >
<TextView
    android:id="@+id/textViewPage"
    android:layout_width = "match_parent"
    android:layout_height= "wrap_content"
    />  
</android.support.v4.view.ViewPager>

But all that did was make the text view disappear from the screen, while the button and red block still cycled as in the original issue.

  • 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-15T08:02:15+00:00Added an answer on June 15, 2026 at 8:02 am

    It seems that you’re using the same XML layout for both the Activity and also for the View that is created by your PageFragment.

    You need at least two layouts. The first layout required is what’s used by the hosting FragmentActivity. This layout would contain your ViewPager, plus other stuff that stays static on the screen alongside the ViewPager, such as the button, etc. This layout is pretty much what you’ve shown (your first XML listing).

    The second layout is the one that would be inflated inside onCreateView() of your PageFragment. Assuming for starters you just want to be flipping between simple TextViews, then the layout that onCreateView() would inflate and return would be a dedicated XML layout that contains just a TextView.

    In other words, the following part of your XML layout:

    <TextView
    android:id="@+id/textViewPage"
    android:layout_width = "match_parent"
    android:layout_height= "wrap_content"
    />  
    

    …needs to be taken out of there and put into a separate layout, such as fragment_layout.xml, and it is that layout that you’d inflate in onCreateView().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a python novice and am struggling with some concepts here - any help
I'm new to Java EE and have been struggling with some basic middleware concepts
Apologies about this simple question. Still struggling with some of the memory concepts here.
struggling a bit to get the following to work : I'm trying to merge
I've been using RDBMSes since college and am really struggling with the underlying concepts
I just started ASP.NET MVC (coming from WebForms) and I'm struggling with some really
I'm struggling with bridging the concepts of good database design with good object orientated
I am struggling (in some sense) to determine which HTTP method is more appropriate
I'm struggling with the following domain design that seams not to fit within the
I am now struggling with Haskell. Even, I have some experience with imperative languages,

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.