J'ai un TabHost avec deux onglets. Je veux savoir quand l'utilisateur clique sur l'un ou l'autre onglet. Comment puis-je atteindre cet objectif?Comment déterminer si un utilisateur a cliqué sur un onglet à l'intérieur d'un TabHost?
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, Main.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("watchlist").setIndicator("Watchlist",res.getDrawable(R.drawable.icon)).setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, ARActivity.class);
spec = tabHost.newTabSpec("trending").setIndicator("Trending",res.getDrawable(R.drawable.icon)).setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
Votre question n'est pas claire. Lorsque l'utilisateur clique sur un onglet, les onglets changeront et l'activité dans le nouvel onglet deviendra active, donc il saura déjà que son onglet a été cliqué. – Squonk
Existe-t-il un moyen d'ajouter un écouteur onclick aux onglets pour que je puisse faire des choses à ce moment-là? –