0

I have a simple app (tabs with Fragment contents) obtained by extending this sample: http://developer.android.com/resources/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentTabs.html.

One of those tabs needs to have a ListView and after clicking an item, details should be displayed on another screen, if the screen is small, or on the same screen, if it's large (or in landscape mode).

I've tried to integrate this sample here: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/FragmentLayout.html, but that one's an activity, not a Fragment, so I can't use:

setContentView(R.layout.fragment_list_layout);

LE more details:

I have a FragmentActivity with a TabHost whose contents are Fragments. One of those Fragments will have to be a ListFragment that can display the details on the same screen as the list, such as this sample from FragmentLayout.java:

enter image description here

I want to get to this functionality using the recommended practices (Fragments as tab contents). Is this possible?

If not, I've tried and managed to start another FragmentActivity when a certain tab is selected. The goal is to use that FragmentActivity as a container for my layout (ListView + fragment) just like in the FragmentLayout example, except that I can't seem to add the previously created tab menu to it. How to get this working then?

Currently:

enter image description here

After selecting "random tab":

enter image description here

My last resort desired look (separate FragmentActivity with the original tabHost):

enter image description here

Buffalo
  • 3,861
  • 8
  • 44
  • 69

1 Answers1

0

I've solved the problem by having two containers inside my tabContent, one for the ListView fragment and one for the details fragment. Here is my layout now:

<HorizontalScrollView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:fillViewport="true"
    android:scrollbars="vertical" >

    <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal" />
</HorizontalScrollView>

<FrameLayout
    android:id="@android:id/tabcontent"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_weight="0" />

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:baselineAligned="false"
    android:fadingEdge="none" >

    <FrameLayout
        android:id="@+android:id/realtabcontent"
        android:layout_width="0px"
        android:layout_height="fill_parent"
        android:layout_weight="1" />

    <FrameLayout
        android:id="@+android:id/details_container"
        android:layout_width="0px"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:visibility="gone" />
</LinearLayout>

Tabs can be handled normally after this.

Buffalo
  • 3,861
  • 8
  • 44
  • 69