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 9165591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:56:35+00:00 2026-06-17T14:56:35+00:00

I am new to using ViewPagers and Fragments together. My app has a ListView

  • 0

I am new to using ViewPagers and Fragments together. My app has a ListView on startup, which bring the user to a details view based on a id that is passed. The problem I’m running into is that the details view has a different layout then the list view. The ViewPager is on the intial screen’s layout, so when using the ViewPager the layout retains the inital layout, which is basically just a status bar at the bottom, which should go away when the user is on the details view.

This is what I have so far:

Main.xml (initial layout on startup, with a status bar)

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
>
        <!-- Footer -->
        <TextView 
                android:id="@+id/status" 
                android:layout_width="match_parent" 
                android:layout_height="wrap_content" 
                android:layout_alignParentBottom="true"
        />
        <!-- Footer -->

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:layout_above="@id/status
     />

 </RelativeLayout>

Main.class

public class Main extends SherlockFragmentActivity
{
    private static int NUMBER_OF_PAGES;  
    private ViewPager mViewPager;  
    private MyFragmentPagerAdapter mMyFragmentPagerAdapter; 
    private static List<Fragment> fragments;

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

        setContentView(R.layout.main);

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

        NUMBER_OF_PAGES = 5;

        fragments = new ArrayList<Fragment>();

        fragments.add(new ListingFragment()); //initial screen that just a ListView

        fragments.add(DetailsFragment.newInstance(1));
        fragments.add(DetailsFragment.newInstance(2));
        fragments.add(DetailsFragment.newInstance(3));
        fragments.add(DetailsFragment.newInstance(4));
    }

    private static class MyFragmentPagerAdapter extends FragmentStatePagerAdapter  {            

        public MyFragmentPagerAdapter(FragmentManager fm) {  
             super(fm);  
        }

        @Override  
        public Fragment getItem(int index) {

            return fragments.get(index);
        }

        @Override  
        public int getCount() {  

             return NUMBER_OF_PAGES;  
        }
   }
}

Details.xml (details view with no status bar)

 <?xml version="1.0" encoding="utf-8"?>

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
        android:orientation="vertical"
        android:layout_width="fill_parent"  
        android:layout_height="fill_parent" 
    >

        <ListView android:id="@android:id/list" 
            android:layout_width="wrap_content"  
            android:layout_height="fill_parent" 
        />

    </RelativeLayout>

DetailsFragment.class

public class DetailsFragment extends SherlockFragmentActivity
{
    private int detailId;

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

    @Override
    public void onActivityCreated(final Bundle icicle)
    {    
        super.onActivityCreated(icicle);
    }

    public static DetailsFragment newInstance(int id) {

        DetailsFragment lf = new DetailsFragment();
        Bundle bundle = new Bundle();
        bundle.putInt("id", id);
        lf.setArguments(bundle);
        return lf;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.details, container, false);

        detailId = getArguments().getInt("id");

        return view;
    }
}
  • 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-17T14:56:36+00:00Added an answer on June 17, 2026 at 2:56 pm

    The ViewPager is on the intial screen’s layout, so when using the
    ViewPager the layout retains the inital layout, which is basically
    just a status bar at the bottom, which should go away when the user is
    on the details view.

    Then don’t put it in the main layout file. If the status is tied to the first fragment then it belong in its view, especially if the DetailsFragment doesn’t need to show that status TextView.

    So remove the status TextView from main.xml and add it to the layout file used in the ListingFragment. If ListingFragment extends ListFragment then create a layout file which contains a ListView with the id(android:id="@android:id/list") + the status TextView and inflate this layout file in the onCreateView.

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

Sidebar

Related Questions

I'm fairly new to Fragments and I have an activity which contains a few
I'm using the new ViewPager -view from the Android compatibility library, and I can't
I'm using a ViewPager together with a FragmentPagerAdapter to host three different fragments [Fragment1][Fragment2][Fragment3]
I am making an app in which i am using ViewPAger and my code
I'm using a ViewPager in my app, with the initial fragment being a ListView
i'm pretty new with Fragments and ViewPager. I'm using ActionBarSherlock and ViewPageIndicator from Jack
I am using fragments to show images/pages.I have one Activity(Main) which contains all the
I'm new using the excellent stuff of css twitter bootstrap and having a problem,
I'm new using Yii framework. I show a list a checkbox. But it's not
I still new using Asp.net with vb.net Protected Sub login_Click(ByVal sender As Object, ByVal

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.