Mise en place de tabHost et Fragment
Bonjour à tous,
Est ce que quelqu'un pourrait m'expliquer comment mettre en place des onglet pour passer d'un fragment a un autre ?
J'ai une application avec une activité principale et deux fragment.
Voila mon code qui plante a la ligne addTab
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTabHost = (TabHost)findViewById(R.id.tabhost);
TabSpec tab1 = mTabHost.newTabSpec("Timer");
TabSpec tab2 = mTabHost.newTabSpec("Seance");
Intent intent = new Intent(this, FTimer.class);
tab1.setIndicator("tab1");
tab1.setContent(intent);
tab2.setIndicator("tab2");
tab2.setContent(intent);
mTabHost.addTab(tab2);
//mTabHost.addTab(tab1);*/ |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabHost
android:id="@+id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TabWidget
android:id="@+id/tabs"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
/>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:text="Button" />
<FrameLayout
android:id="@+id/tabcontent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
</TabHost>
</LinearLayout> |
Tout les tutos/forum que j'ai regarder implémente des intents. Mais a quoi ca sert car si j'ai bien compris les intents permettent de faire communiquer plusieurs activités or moi je n'en est qu'une. Je suis complétement perdu a force entre les fragment/intent/activity...
J'ai passé une grande partie de ma journée et soirée a chercher mais je ne trouve rien et la doc android est plutot mal foutu je trouve. Pas d exemple concret e tout cas.
Bonne journée et merci d'avance