Aller au contenu
View in the app

A better way to browse. Learn more.

Forum de Frandroid

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[TUTO]: les Onglets

Featured Replies

Posté(e)

Problème de sylvain résolu et le tuto est posté au post #13

(Edit Profete162)

Bonjour,

Je suis tout nouveau dans cette communauté et sur Android (J'ai acquis mon Desire il y'a quelques jours ^^)

Donc, comme tout bon nouveau programmeur sur Android, j'ai tenté de réaliser des onglets. Et malgrès de nomvreux essais (j'y suis depuis ce matin 9h), lors du lancement de l'application, l'émulateur met dit "Sorry the application...has stopped unexpectedly. Please try again".

Au tout début j'essayais de faire quelque chose de personnalisé, mais maintenant j'essaie simplement de faire marcher le code qui est dans le guide du développeur, donné par Google. J'ai même corrigé les erreurs qui y sont (à savoir l'ajout de 3 dans le manifest ainsi que tabHost.setCurrentTab(0) à la place de celui avec le getIntent();

Malgré de nombreuses recherches, je reste en échec.... Je me tourne donc vers vous, avant d'envisager de me pendre ^^.

Voici les divers codes (Je précise que c'est du pur copier coller de google, mis à part les corrections d'erreur) :

la classe principale héritant de TabActivity

package test.hello;

import android.app.TabActivity;

import android.content.Intent;

import android.content.res.Resources;

import android.os.Bundle;

import android.widget.TabHost;

public class HelloTabWidget extends TabActivity {

/** Called when the activity is first created. */

@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, ArtistsActivity.class);

// Initialize a TabSpec for each tab and add it to the TabHost

spec = tabHost.newTabSpec("artists").setIndicator("Artists", res.getDrawable(R.drawable.ic_tab_artists)).setContent(intent);

tabHost.addTab(spec);

// Do the same for the other tabs

intent = new Intent().setClass(this, AlbumsActivity.class);

spec = tabHost.newTabSpec("albums").setIndicator("Albums",res.getDrawable(R.drawable.ic_tab_albums)).setContent(intent);

TabHost.addTab(spec);

intent = new Intent().setClass(this, SongsActivity.class);

spec = tabHost.newTabSpec("songs").setIndicator("Songs", res.getDrawable(R.drawable.ic_tab_songs)).setContent(intent);

tabHost.addTab(spec);

tabHost.setCurrentTab(0);

}

}

le manifest.xml

package="test.hello"

android:versionCode="1"

android:versionName="1.0">

android:label="@string/app_name">

android:label="@string/a_name">

android:label="@string/b_name">

android:label="@string/c_name">

<?xml version="1.0" encoding="utf-8"?>

android:id="@android:id/tabhost"

android:layout_width="fill_parent"

android:layout_height="wrap_content">

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:padding="5dp">

android:id="@android:id/tabs"

android:layout_width="fill_parent"

android:layout_height="wrap_content" />

android:id="@android:id/tabcontent"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:padding="5dp" />

Le code type que j'ai mis pour chaque activity

package test.hello;

import android.app.Activity;

import android.os.Bundle;

import android.widget.TextView;

public class AlbumsActivity extends Activity {

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

TextView txt=new TextView(this);

txt.setText("hola tata");

setContentView(txt);

}

}

Je vous remercie par avance pour vote aide

Posté(e)

Juste un petit truc avant de passer 10 minutes à lire ton code...

Une copie de l'erreur renvoyée par le logcat pourrait nous aider à cibler directement le probleme...

Re-Edit:

Mon premier édit était n'importe quoi...

Modifié par Profete162

Posté(e)
  • Auteur

Ah, déjà merci de répondre :).

Par contre, le logcat... On le trouve ou? ^^ (désolé :( )

Ah, je viens de voir ton message, je vais modifier les activités alors, je te tiens au courant

Modifié par Sylvain-a

Posté(e)

Le logcat, c'est le truc le plus important quand tu développes, c'est là que passent tous les messages,n ton débug et ou sont listées les erreurs!

Il se trouve dans éclipse normalement. Regarde dans les onglets que tu peux rajouter, c'est super important.

Posté(e)
  • Auteur

Alors, j'ai trouvé le logcat dans Eclipse, merci à vous 2pour ça :).

Donc, pour commencer, j'ai suivi ton conseil quant aux xml. Ca ne règle pas le problème :(, voici le code du xml que j'ai rajouté :

<?xml version="1.0" encoding="utf-8"?>

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="wrap_content"

android:layout_height="wrap_content">

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:text="@string/hello"/>

(j'ai modifié les setContentView() bien entendu )

Voici ce que me dit la console d'Eclipse :

[2010-05-16 17:21:05 - HelloTabWidget] ActivityManager: Warning: Activity not started, its current task has been brought to the front

Et voici le logcat, je précise que maintenant, l'émulateur m'affiche seulement un écran noir, plus d'erreur de lancement, mais si j'interprete bien le logcat c'est parce qu'il n'arrive pas à démarrer le processus :

05-16 15:21:04.975: INFO/ActivityManager(51): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=test.hello/.HelloTabWidget }

05-16 15:21:05.015: DEBUG/AndroidRuntime(303): Shutting down VM

05-16 15:21:05.015: DEBUG/dalvikvm(303): DestroyJavaVM waiting for non-daemon threads to exit

05-16 15:21:05.015: DEBUG/dalvikvm(303): DestroyJavaVM shutting VM down

05-16 15:21:05.015: DEBUG/dalvikvm(303): HeapWorker thread shutting down

05-16 15:21:05.025: DEBUG/dalvikvm(303): HeapWorker thread has shut down

05-16 15:21:05.025: DEBUG/jdwp(303): JDWP shutting down net...

05-16 15:21:05.025: INFO/dalvikvm(303): Debugger has detached; object registry had 1 entries

05-16 15:21:05.035: DEBUG/dalvikvm(303): VM cleaning up

05-16 15:21:05.065: ERROR/AndroidRuntime(303): ERROR: thread attach failed

05-16 15:21:05.105: DEBUG/dalvikvm(303): LinearAlloc 0x0 used 638596 of 5242880 (12%)

05-16 15:21:07.295: WARN/WindowManager(51): No window to dispatch pointer action 0

05-16 15:21:07.405: WARN/WindowManager(51): No window to dispatch pointer action 1

05-16 15:21:07.855: WARN/WindowManager(51): No window to dispatch pointer action 0

05-16 15:21:08.175: WARN/WindowManager(51): No window to dispatch pointer action 1

05-16 15:21:14.989: WARN/ActivityManager(51): Launch timeout has expired, giving up wake lock!

05-16 15:21:15.000: WARN/ActivityManager(51): Activity idle timeout for HistoryRecord{43d920a8 test.hello/.HelloTabWidget}

05-16 15:21:20.065: DEBUG/dalvikvm(97): GC freed 314 objects / 16792 bytes in 70ms

Posté(e)

euhh en fait ce que j'ai dit au premier post à rien à voir, je m'étais planté et ce n'était pas cela qui fait planter ton appli...

Ton code était bon.

Posté(e)
  • Auteur

Ah ok, merci quand même ^_^, t'aurais une autre idée? :)

Ou alors si quelqu'un à un code "simple" pour exemple; qui marche chez lui... je suis prêt à prendre pour comprendre là.

Modifié par Sylvain-a

Posté(e)

Je te balance du code en vrac:

Normalement pas besoin de xml ou quoi que ce soit:

package xxx.xxx.xxx;

public class MonTab extends TabActivity{

   public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setFullscreen();
   TabHost host=getTabHost();
   host.setup();

   host.addTab(host.newTabSpec("All")
   .setIndicator("", this.getResources().getDrawable(R.drawable.icon))
   .setContent(new Intent(this, GetStation.class)));


   host.addTab(host.newTabSpec("Europe")
   .setIndicator("", this.getResources().getDrawable(R.drawable.europe))
   .setContent(new Intent(this, GetEuroStation.class)));


   host.addTab(host.newTabSpec("Favorites")
   .setIndicator("", this.getResources().getDrawable(R.drawable.star))
   .setContent(new Intent(this, GetFavStation.class)));

   }


   public void setFullscreen() {
       requestWindowFeature(Window.FEATURE_NO_TITLE);
       getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
               WindowManager.LayoutParams.FLAG_FULLSCREEN);
   }

}

Posté(e)
  • Auteur

Merci beaucoup... Mais j'ai essayé ton code, j'ai toujours le même problème... Ca pourrait venir de l'émulateur? (j'ai essayé redémarrer Eclipse tout à l'heure, mais ça n'a rien change)

voici le logcat, a priori, y'a beaucoup d'erreurs :

05-16 15:54:58.305: INFO/ActivityManager(51): Start proc sly.essai for activity sly.essai/.MonTab: pid=345 uid=10025 gids={1015}

05-16 15:54:58.315: ERROR/AndroidRuntime(339): ERROR: thread attach failed

05-16 15:54:58.375: DEBUG/dalvikvm(339): LinearAlloc 0x0 used 638596 of 5242880 (12%)

05-16 15:54:58.515: DEBUG/ddm-heap(345): Got feature list request

05-16 15:54:58.705: DEBUG/AndroidRuntime(345): Shutting down VM

05-16 15:54:58.705: WARN/dalvikvm(345): threadid=3: thread exiting with uncaught exception (group=0x4001b188)

05-16 15:54:58.715: ERROR/AndroidRuntime(345): Uncaught handler: thread main exiting due to uncaught exception

05-16 15:54:58.725: ERROR/AndroidRuntime(345): java.lang.Error: Unresolved compilation problems:

05-16 15:54:58.725: ERROR/AndroidRuntime(345): R.drawable.barcode cannot be resolved

05-16 15:54:58.725: ERROR/AndroidRuntime(345): R.drawable.cards cannot be resolved

05-16 15:54:58.725: ERROR/AndroidRuntime(345): R.drawable.chart cannot be resolved

05-16 15:54:58.725: ERROR/AndroidRuntime(345): at sly.essai.MonTab.onCreate(MonTab.java:20)

05-16 15:54:58.725: ERROR/AndroidRuntime(345): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)

05-16 15:54:58.725: ERROR/AndroidRuntime(345): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)

05-16 15:54:58.725: ERROR/AndroidRuntime(345): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)

05-16 15:54:58.725: ERROR/AndroidRuntime(345): at android.app.ActivityThread.access$2200(ActivityThread.java:119)

05-16 15:54:58.725: ERROR/AndroidRuntime(345): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)

05-16 15:54:58.725: ERROR/AndroidRuntime(345): at android.os.Handler.dispatchMessage(Handler.java:99)

05-16 15:54:58.725: ERROR/AndroidRuntime(345): at android.os.Looper.loop(Looper.java:123)

05-16 15:54:58.725: ERROR/AndroidRuntime(345): at android.app.ActivityThread.main(ActivityThread.java:4363)

05-16 15:54:58.725: ERROR/AndroidRuntime(345): at java.lang.reflect.Method.invokeNative(Native Method)

05-16 15:54:58.725: ERROR/AndroidRuntime(345): at java.lang.reflect.Method.invoke(Method.java:521)

05-16 15:54:58.725: ERROR/AndroidRuntime(345): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)

05-16 15:54:58.725: ERROR/AndroidRuntime(345): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)

05-16 15:54:58.725: ERROR/AndroidRuntime(345): at dalvik.system.NativeStart.main(Native Method)

05-16 15:54:58.745: INFO/Process(51): Sending signal. PID: 345 SIG: 3

05-16 15:54:58.755: INFO/dalvikvm(345): threadid=7: reacting to signal 3

05-16 15:54:58.755: ERROR/dalvikvm(345): Unable to open stack trace file '/data/anr/traces.txt': Permission denied

05-16 15:55:08.583: WARN/ActivityManager(51): Activity idle timeout for HistoryRecord{43ca50e8 sly.essai/.MonTab}

05-16 15:55:13.645: DEBUG/dalvikvm(203): GC freed 123 objects / 5376 bytes in 62ms

05-16 15:55:18.665: DEBUG/dalvikvm(313): GC freed 863 objects / 53968 bytes in 72ms

Bien sur je l'ai adapté au cas présent (j'ai changé le noms des classes).

Il semble aussi qu'il n'arrive pas à trouver les R.drawable.x alors que pourtant.... j'ai bien un dossier drawable avec à l'intérieur 3 images png portant les noms correspondant au code

Modifié par Sylvain-a

Posté(e)

à la ligne 20 de MonTab.java il y a quoi? tu appelles tes 3 images en meme temps ou quoi??

Viens sur Gtalk, ce sera plus facile. adresse envoyée en MP

Posté(e)
  • Auteur

Ok, c'est fait, je t'ai invité :)

PS : voici la ligne 20 :

host.addTab(host.newTabSpec("All")

.setIndicator("", this.getResources().getDrawable(R.drawable.barcode))

.setContent(new Intent(this, AlbumsActivity.class)));

Modifié par Sylvain-a

Posté(e)

Pour ceux que cela intéresse voici la démo que je lui ai envoyé.

Rien de magique, juste quelques lignes de code

Posté(e)

à noter qu'on peut aussi mettre de simple vues dans une TabActivity, et non d'autres Activities :D

Rejoignez la conversation

Vous pouvez poster maintenant et vous enregistrez plus tard. Si vous avez un compte, connectez-vous maintenant pour poster.

Invité
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Répondre à ce sujet…

Account

Navigation

Rechercher

Rechercher

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.