J'écris une application pour Android qui nécessite des onglets et j'ai le contenu de ma liste de roulement sur mes onglets. Je sais que ça doit être quelque chose de simple, mais je ne le trouve pas.Android: Conteneur de contenu
Voici mon main.xml
<TabWidget android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="@android:id/tabs" />
<FrameLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:id="@android:id/tabcontent">
</FrameLayout>
et voici le code java
public class étend à nouveau TabActivity { @Override onCreate public void (Bundle savedInstanceState) { super.onCréer (s avedInstanceState); 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, Download.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("download")
.setIndicator("", res.getDrawable(R.drawable.ok))
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, Settings.class);
spec = tabHost.newTabSpec("settings")
.setIndicator("", res.getDrawable(R.drawable.ok))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
}
}
Toute aide serait grandement apprécié.
Jason
Y a-t-il une raison pour laquelle vous appelez setContentView sur une tabactivité? Vous ne devriez pas le faire en général. C'est presque certainement parce que votre framelayout est réglé sur fill_parent. Vous n'avez pas besoin d'une vue pour une tabactivité, il a tout interne. – Falmarri