1

I am getting overlapped Fragments in PageViewer of Android .

PFB my layout for PageViewer

<TabHost
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="900dp"
    android:layout_alignParentBottom="true" >

  <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_above="@android:id/tabs" >

            <android.support.v4.view.ViewPager
                android:id="@+id/viewpager"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" >
            </android.support.v4.view.ViewPager>
        </FrameLayout>

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:orientation="horizontal" >
        </TabWidget>
    </RelativeLayout>
</TabHost>

I am calling it via my First Fragment Say FragmentA of first Tab . I need to replace it with Fragment A1 Calling this from the button click of list from BaseAdapter

Fragment duedateFrag = new FieldVisitFragment();
            FragmentTransaction ft = fragmentActivity.getSupportFragmentManager().beginTransaction();
            ft.replace(android.R.id.tabcontent, duedateFrag);

            ft.commit();

My Fragment gets called but its overlapped on viewpager . The tabs runs from below the new Fragment . kindly help

On the hindsight , I think somewhere Nested Fragment or Child Fragment should come into play . Please guide.

Project Android
  • 575
  • 4
  • 16

1 Answers1

1

I have used ViewPager, extending from PagerAdapter. I think you're not referencing the correct layout, you're using id/tabcontent. I can show an example of what I did, and I think you can follow the same.

In the Fragment xml:

<LinearLayout
...
<android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="0px"
        android:layout_weight="1"
        android:background="@android:color/white" />
...
</LinearLayout>

In Fragment code :

mViewPager = (ViewPager) view.findViewById(R.id.viewpager);

In the ViewPager code,

@Override
public Object instantiateItem(ViewGroup container, int position) {
...
View view = getActivity().getLayoutInflater().inflate(R.layout.pager_item, container, false);
...
return view
}

Note: I did not use FragmentTransaction class for displaying the fragment or the tab view.

Keep us posted...

The Original Android
  • 6,147
  • 3
  • 26
  • 31
  • @Original Android : I have posted alternate question with total developmnents https://stackoverflow.com/questions/30233001/fragment-does-not-get-displayed-in-viewpager – Project Android May 15 '15 at 05:07
  • @ProjectAndroid, This is almost like answering twice for the same "alternate" question. Perhaps better would be just to edit your original question, though a lot changed. This way many comments are kept. Do you think my current posted answer is helpful at all? – The Original Android May 15 '15 at 05:58