Je veux créer une application avec des onglets, et j'ai trouvé ce guide http://developer.android.com/resources/tutorials/views/hello-tabwidget.html sur Internet, j'ai choisi de suivre.Onglets Android avec TableLayout
J'ai créé un fichier XML pour la mise en page, qui ressemble à ceci:
<?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="50dip">
<LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="5dp">
<TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" />
<FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="5dp">
<TableLayout android:id="@+id/aTableLayout" android:layout_width="fill_parent" android:layout_height="fill_parent">
</TableLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
J'ai aussi créé une classe pour créer les onglets en raison du guide, qui est illustré ci-dessous. Maintenant, j'ai besoin de générer le contenu des onglets, où l'un des onglets est GuiRegistration.
J'ai conçu le GuiRegistration dans un fichier XML, mais j'ai aussi besoin d'ajouter des actions aux boutons par exemple, donc je dois utiliser la classe GuiRegistration.
Mais comment puis-je créer l'onglet, parce que je l'ai essayé d'utiliser
setContentView(R.layout.registration)
design l'onglet directy dans la classe
Et
public class GuiRegistration extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View aTabLayout = findViewById(R.id.aTableLayout);
ViewGroup vGroup = (ViewGroup) aTabLayout.getParent();
int index = vGroup.indexOfChild(aTabLayout);
vGroup.removeViewAt(index);
View newTabLayout = getLayoutInflater().inflate(R.layout.registration, vGroup, false);
vGroup.addView(newTabLayout, index);
}
}
Mais rien ne semble fonctionner, quelqu'un peut dire moi comment le faire fonctionner?
Votre question n'est pas claire, s'il vous plaît être plus précis –
Je pense que vous avez besoin de tabhost aussi. – Tsunaze
J'ai édité la question maintenant, donc j'espère que cela la rendra plus claire – The87Boy