Android wie die Interaktion mit Fragment tabs

Hallo, ich habe Schwierigkeiten beim ändern der visuellen Sicht auf die fragment-Aktivität. Erstellt habe ich alle tabs aber onClick-ich weiß nicht, wie das passieren der Aktivität in diesem weißen Raum.

http://i40.tinypic.com/22bwxx.png

also die Struktur dies ist eine einfache Aktivität mit dem Namen Main die stellt nur die Inhalte anzeigen, um eine maintabholder.xml Dokument, das hält die fragment-Ansicht, die eine Verbindung zu einer benannten Klasse MainNav deren Inhalte-Ansicht enthält alle Registerkarten am unteren Rand.

maintabholder.xml:

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>

<include layout="@layout/header" android:layout_alignParentTop="true"           android:id="@+id/headerArea"></include>
<fragment
    class="my.package.name.MainNav"
    android:id="@+id/fragment_tabs"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />
</LinearLayout>

MainNav.java code snippet:

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) 
{
    mRoot = inflater.inflate(R.layout.fragment_tabs, null);
    mTabHost = (TabHost) mRoot.findViewById(android.R.id.tabhost);
    setupTabs();
    return mRoot;
}

und R. layout.fragment_tabs:

<?xml version="1.0" encoding="utf-8"?>
<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#EFEFEF">

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

    <TabWidget
        android:id="@android:id/tabs"
        android:layout_alignParentBottom="true"
        android:layout_width="fill_parent"
        android:background="@drawable/tab_background"
        android:gravity="center_horizontal"
        android:layout_height="wrap_content" >
    </TabWidget>

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"

            android:layout_height="wrap_content">

            <FrameLayout
                android:id="@+id/tab_1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <FrameLayout
                android:id="@+id/tab_2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
             <FrameLayout
                android:id="@+id/tab_3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
              <FrameLayout
                android:id="@+id/tab_4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
               <FrameLayout
                android:id="@+id/tab_5"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

        </FrameLayout>
</RelativeLayout>

und Schließlich der Inhalt einer Aktivität, die ich laden will in dem Fragment (nach dem drücken der tab1-Taste)

 public class HomeFragment extends Activity {


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.home);

    }
 }

Ist, Ihnen zu helfen, den Kern der Dinge, aber das problem tritt hier in MainNav.java:

  @Override
   public void onTabChanged(String tabId) {
        Log.d(TAG, "onTabChanged(): tabId=" + tabId);
        if (TAB_HOME.equals(tabId)) {
            updateTab(tabId, R.id.tab_1);
            mCurrentTab = 0;
            return;
        }
   }

wenn eine Registerkarte geklickt wird, ist es eingetragen in den onTabChanged Aktivität, und die updateTab Funktion aufgerufen wird:

   private void updateTab(String tabId, int placeholder) {
        FragmentManager fm = getFragmentManager();
        if (fm.findFragmentByTag(tabId) == null) {
            //fm.beginTransaction()
             //     .replace(placeholder, /*need fragment object here*/, tabId)
             //      .commit();
            //
        }
}

den auskommentierten replace Methode ist für eine Suche (int, fragment, string) und ich denke, es sollten dann ändern Sie den weißen Raum für mich.

aber ich verstehe nicht, wo bekomme ich die fragment-Objekt aus! Das phantom-Objekt muss irgendwie enthalten meine HomeFragment's xml-layout und erlauben Sie mir zu interagieren, mit allem, was ich codiert haben für die HomeFragment Aktivität.

Meine erste Vermutung ist, dass mein HomeFragment Aktivität muss extend FragmentActivity statt
nur Aktivität. Aber das ist, wo ich bin gegen eine Wand.

Es gibt sehr wenig Dokumentation über das compatibility pack Methoden, aber die Dokumentation für TabActivity sagt nicht zu verwenden, TabActivity mehr, also hier bin ich. Die Entwicklung für Android 2.2+

Einblick geschätzt.

InformationsquelleAutor CQM | 2011-11-09

Schreibe einen Kommentar