Salut, je suis le tutoriel suivant fourni par nom de hello-tabwidget. Pour créer un onglet. Tout fonctionne bien, mais maintenant je veux ajouter un bouton à un onglet, mais ce bouton apparaît dans tous les onglets.en utilisant l'onglet Mise en page dans android - Le bouton ajouté à un onglet apparaît dans tous les onglets
S'il vous plaît quelqu'un peut-il vous aider?
Merci
ce que j'ai
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, FirstTab.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("First Tab").setIndicator("First Tab",
res.getDrawable(R.drawable.ic_tab_artists))
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, SecondTab.class);
spec = tabHost.newTabSpec("Second Tab").setIndicator("Second Tab",
res.getDrawable(R.drawable.ic_tab_albums))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, ThirdTab.class);
spec = tabHost.newTabSpec("Third Tab").setIndicator("Third Tab",
res.getDrawable(R.drawable.ic_tab_songs))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, NextTab.class);
spec = tabHost.newTabSpec("Next Tab").setIndicator("Next Tab",
res.getDrawable(R.drawable.ic_tab_next))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
}
}
main.xml
<?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" >
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp">
<include layout="@layout/tab1"/>
<include layout="@layout/tab2"/>
<include layout="@layout/tab3"/>
<include layout="@layout/tab4"/>
</FrameLayout>
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="bottom"/>
</LinearLayout>
</TabHost>
J'ai créé la mise en page de xml pour chaque onglet c'est un avec le bouton autres sont exactement ce même juste avec une étiquette de bouton et avec l'ID différent
tab2.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tab2Layout"
android:orientation="vertical">
<Button android:text="@+id/Button01"
android:id="@+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</Button>
</LinearLayout>
et j'ai créé la classe pour chaque onglet ce code est de la deuxième onglet où je veux avoir un bouton les autres classes sont exactement la même que
setContentView(R.layout.tab2);
est réglé Point de différentes configurations
SecondTab.java
public class SecondTab extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tab2);
}
}
An y idées ??
Merci