IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Android Discussion :

[TabHost et LinearLayout] Erreur avec TabHost


Sujet :

Android

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Homme Profil pro
    -
    Inscrit en
    Novembre 2007
    Messages
    64
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : -

    Informations forums :
    Inscription : Novembre 2007
    Messages : 64
    Par défaut [TabHost et LinearLayout] Erreur avec TabHost
    Bonjour,

    J'aimerai pouvoir insérer un TabHost dans mon application, mais le problème est qu'il est situé dans un relativeLayout, et est appelé par un include, ce qui me donne l'erreur suivante :

    Caused by: java.lang.RuntimeException: Your content must have a TabHost whose id attribute is 'android.R.id.tabhost'

    Voici mon main.xml :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout 
    	android:id="@+id/relativeLayout1" 
    	android:layout_width="fill_parent" 
    	android:layout_height="fill_parent"
    	android:background="@color/backgroundColor" 
    	xmlns:android="http://schemas.android.com/apk/res/android">
    	<include
    	        layout="@layout/barreprinc"
    	        android:id="@+id/barreprinc"
    	        android:layout_alignParentTop="true" 
    	/>
    	<FrameLayout
    		android:id="@+id/FrameLayoutAccueil"
    		android:layout_width="wrap_content"
    		android:layout_height="wrap_content"
    		android:layout_centerInParent="true">
    		<include
    			layout="@layout/pagerechpublication"
    		    android:id="@+id/milieu"
    		/>
    	</FrameLayout>
    [...]
    </RelativeLayout>
    Et mon pagerechpublication.xml :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    <?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">
     
    	<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">
     
    	</FrameLayout>
    </LinearLayout>
     
    </TabHost>
    Enfin, voici mon application principale :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    public class irdesApplication extends TabActivity {
     
        public static final String LOG_TAG="Droidnova";
        ListView listViewActu;
        List<Actualite> listeActu = new ArrayList<Actualite>();
     
     
     
        public void onCreate(Bundle savedInstanceState) {
     
            super.onCreate(savedInstanceState);
            setContentView(R.layout.tab);
            requestWindowFeature(Window.FEATURE_NO_TITLE);
            String valeur = getIntent().getStringExtra("valeur");
            TextView textView = (TextView) findViewById(R.id.monTextView);
            textView.setText(valeur);
     
            //constitution des logs
            int logParam =0;
            Log.v(LOG_TAG, "logParam value" + logParam);
     
     
            listViewActu = (ListView)findViewById(R.id.listViewActu);
            Actualite actu1 = new Actualite("Titre1", "Description de l'actualité");
            Actualite actu2 = new Actualite("Titre2", "Description de l'actualité");
     
    	listeActu.add(actu1);
    	listeActu.add(actu2);
     
    	ActuAdapter adapter = new ActuAdapter(this, listeActu);
    	listViewActu.setAdapter(adapter);
     
     
     
        }
    }
    Comment résoudre le problème ?

  2. #2
    Membre confirmé
    Profil pro
    Inscrit en
    Septembre 2007
    Messages
    101
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2007
    Messages : 101
    Par défaut
    Hello,

    Je pense que ton erreur vient de là:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    setContentView(R.layout.tab);
    Essaie de remplacer ça par:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    setContentView(R.layout.pagerechpublication);

  3. #3
    Membre confirmé
    Homme Profil pro
    -
    Inscrit en
    Novembre 2007
    Messages
    64
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : -

    Informations forums :
    Inscription : Novembre 2007
    Messages : 64
    Par défaut
    J'ai fini par trouver la solution, merci pour ta réponse groXx.

    Voici mon code :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
     private void initRechTab(){
     
        	TabHost tabs=(TabHost)findViewById(R.id.tabhost);
     
    		tabs.setup();
     
    		TabHost.TabSpec spec=tabs.newTabSpec("tagViewProg");
     
    		spec.setContent(R.id.listViewPubli);
    		spec.setIndicator("Publications");
    		tabs.addTab(spec);
     
    		spec=tabs.newTabSpec("tag2");
    		spec.setContent(R.id.tab2);
    		spec.setIndicator("Programmes");
    		tabs.addTab(spec);
    		spec=tabs.newTabSpec("tag3");
    		spec.setContent(R.id.tab3);
    		spec.setIndicator("Séminaires");
    		tabs.addTab(spec);
        }
    Et le xml :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    <?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout 
    	xmlns:android="http://schemas.android.com/apk/res/android" 
    	android:layout_width="fill_parent" 
    	android:layout_height="fill_parent"> 
    	<TabHost 
    		android:id="@+id/tabhost" 
    	    android:layout_width="fill_parent" 
    	    android:layout_height="fill_parent"> 
    	    <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:paddingTop="70dip"> 
    		    <FrameLayout 
    		    android:id="@+id/FrameLayoutListViewPubli" 
    		    android:layout_width="fill_parent" 
    		    android:layout_height="fill_parent"> 
    		    	<ListView
    					android:id="@+id/listViewPubli"
    					android:layout_width="fill_parent"
    					android:layout_height="wrap_content"
    				/>
    			</FrameLayout>
    	      	<Button 
    			    android:id="@+id/tab2" 
    			    android:layout_width="fill_parent" 
    			    android:layout_height="fill_parent" 
    			    android:text="Bouton" 
    	      	/> 
    	      	<Button 
    			    android:id="@+id/tab3" 
    			    android:layout_width="fill_parent" 
    			    android:layout_height="fill_parent" 
    			    android:text="Bouton" 
    	     	/> 
    		</FrameLayout> 
    	</TabHost> 
    </RelativeLayout>

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Erreur création TabHost
    Par Matf4ke dans le forum Android
    Réponses: 1
    Dernier message: 28/11/2012, 13h43
  2. Réponses: 11
    Dernier message: 04/06/2011, 02h45
  3. Problème avec TabHost et tabWidget
    Par lupus83 dans le forum Android
    Réponses: 4
    Dernier message: 08/02/2011, 19h28
  4. OptionMenu avec TabHost
    Par jonathantarabbia dans le forum Android
    Réponses: 5
    Dernier message: 17/01/2011, 22h10
  5. Erreur avec WM_COMMAND (BN_CLICKED)
    Par cyberlewis dans le forum Windows
    Réponses: 2
    Dernier message: 09/02/2004, 00h25

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo