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 :

Problème d'affichage avec mon application


Sujet :

Android

  1. #1
    Membre à l'essai
    Homme Profil pro
    Etudiant
    Inscrit en
    Mars 2014
    Messages
    28
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 30
    Localisation : Suisse

    Informations professionnelles :
    Activité : Etudiant

    Informations forums :
    Inscription : Mars 2014
    Messages : 28
    Points : 21
    Points
    21
    Par défaut Problème d'affichage avec mon application
    Hello !

    je suis actuellement entrain d'essayer de développer une application pour faciliter l'identification d'insectes et aussi pour apprendre a développer une application pour android.

    Tous se passe bien au début mon émulateur m'affiche bien mon premier layout mais je n'arrive pas à cliquer sur un bout afin d'afficher le deuxième layout. Pourriez vous m'aider ?

    le main :
    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
    45
    46
    47
    48
    49
    50
    51
    52
    53
    package android.Choix;
     
    import android.R;
    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.Toast;
     
    public class Main extends Activity implements OnClickListener
    {
        private static final int INSECTES = 0;   
        public Button [] listeBoutons = new Button[1];
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            setContentView(0x7f030000);
     
            listeBoutons[INSECTES] = ((Button)this.findViewById(0x7f050001));
        }
     
        public void onClick(View v){
            String msg="";
            int parametre = v.getId();
            creerAcrivite (parametre);
            switch (parametre){
                case 0x7f050001 :
                    msg = "Insectes";
                    break;
                case 0x7f050002:
                    msg ="Plantes";
                    break;
     
            }
            Toast msgT = Toast.makeText(this,msg,Toast.LENGTH_SHORT);
            msgT.show();
        }
     
        public void creerAcrivite(int activite){
            Intent nvActivite ;
            switch (activite){
                    case INSECTES:
            nvActivite = new Intent (Main.this, Coleoptera.class);
            startActivityForResult(nvActivite, INSECTES);  
     
           }
        }
     
    }

    qui lance le layout accueil :

    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
    <?xml version="1.0" encoding="utf-8"?>
     
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#FFFFFFFF"
        android:id="@+id/accueil"
        >
    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/insectes"
        android:id="@+id/insectes"
        android:layout_marginTop="2px"
        />
    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/plantes"
        android:id="@+id/plantes"
        android:layout_marginTop="2px"
     
        />
    </LinearLayout>
    qui lui devrait ensuite lancer le coleoptera.java

    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
    45
    46
    47
    48
    package android.Choix;
     
    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
     
    /**
     *
     * @author Asus
     */
    public class Coleoptera extends Activity  implements OnClickListener{
        private static final int POLYPHAGA = 0;
        private static final int ADEPHAGA = 1 ;  
     
        public Button [] listeBoutons = new Button[1];
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            setContentView(0x7f030001);
     
            listeBoutons[POLYPHAGA] = ((Button)this.findViewById(0x7f050005));
            listeBoutons[ADEPHAGA] = ((Button)this.findViewById(0x7f050004));
        }
     
        public void onClick(View v){
     
            int parametre = v.getId();
            //creerAcrivite (parametre);
        }
       /* public void creerAcrivite(int activite){
            Intent nvActivite ;
            switch (activite){
                    case POLYPHAGA:
            nvActivite = new Intent (Main.this, Polyphaga.class);
            startActivityForResult(nvActivite, INSECTES);  
                        
           }
                nvActivite = new Intent (Main.this, Coleoptera.class);
            startActivityForResult(nvActivite, INSECTES);  
                        
           }
        */
    }
    qui lui même appelle le layout coleoptera

    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
    <?xml version="1.0" encoding="utf-8"?>
     
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#FFFFFFFF"
        android:id="@+id/Coleoptera"
        >
      <ImageView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/adephaga"
        android:layout_marginTop="5px"
      />     
    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Hanches postérieures dépassant le bord postérieur du premier segment abdominal visible"
        android:id="@+id/Adephaga"
        android:layout_marginTop="2px"
        />
     
     <ImageView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/polyphaga"
        android:layout_marginTop="5px"
      />
    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Hanches postérieures ne dépassant pas le bord postérieur du premier segment abdominal visible"
        android:id="@+id/Polyphaga"
        android:layout_marginTop="2px"
     
        />
    </LinearLayout>
    pour finir mon fichier manifest

    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
    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="android.Choix"
          android:versionCode="1"
          android:versionName="1.0">
        <application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
            <activity android:name="Main"
                      android:label="@string/app_name">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
            <activity
            android:name=".Coleoptera"
            android:label="Choisir une option"
            />
        </application>
    </manifest>

    Voilà j'imagine que mon erreur est toute simple mais je ne la trouve ...

    Pourriez vous m'aider ou il vous faut plus d'info ?

    PS: j'ai mis directement l'adresse des fichiers car le R.id.(nom du fichier) ne marche pas.

  2. #2
    Membre éprouvé
    Avatar de ChPr
    Homme Profil pro
    Inscrit en
    Septembre 2005
    Messages
    2 032
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 78
    Localisation : France, Val d'Oise (Île de France)

    Informations forums :
    Inscription : Septembre 2005
    Messages : 2 032
    Points : 1 052
    Points
    1 052
    Par défaut
    J'ai cru comprendre qu'il ne fallait jamais faire d'import explicite de "android.R". C'est peut-être d'ailleurs la raison pour laquelle vous ne pouvez pas accéder à vos layout.

    Cordialement.

    Pierre

  3. #3
    Expert confirmé
    Avatar de Hephaistos007
    Profil pro
    Enseignant Chercheur
    Inscrit en
    Décembre 2004
    Messages
    2 493
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Enseignant Chercheur
    Secteur : Enseignement

    Informations forums :
    Inscription : Décembre 2004
    Messages : 2 493
    Points : 4 166
    Points
    4 166
    Par défaut
    Citation Envoyé par Nanonnien Voir le message
    PS: j'ai mis directement l'adresse des fichiers car le R.id.(nom du fichier) ne marche pas.
    C'est parce qu'il y a confusion entre la classe R native de android et ta classe R à toi. Enlèves l'import android.R pour le remplacer par le tiens. Et au passage, c'est une très mauvaise idée d'avoir nommé ton package android ! gare aux confusions en séries ! Changes en com.Nanonnien par exemple.

  4. #4
    Membre à l'essai
    Homme Profil pro
    Etudiant
    Inscrit en
    Mars 2014
    Messages
    28
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 30
    Localisation : Suisse

    Informations professionnelles :
    Activité : Etudiant

    Informations forums :
    Inscription : Mars 2014
    Messages : 28
    Points : 21
    Points
    21
    Par défaut
    Oups merci =) ! J'ai simplement suivi le tuto "le livre de java comme premier langage" donc désolé de es erreurs de débutant. Maintenant le nannonnien.Choix.R.* marche. Mais je n'arrive toujours pas à faire ouvrir ouvrir ma deuxième activité.

  5. #5
    Membre éclairé
    Avatar de LeBzul
    Homme Profil pro
    Inscrit en
    Décembre 2008
    Messages
    381
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Meurthe et Moselle (Lorraine)

    Informations forums :
    Inscription : Décembre 2008
    Messages : 381
    Points : 832
    Points
    832
    Par défaut
    Salut,
    Il faut ajouter un listener à tes boutons :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    Button b=(Button)findViewId(R.id.xxxx);
    b.setOnClickListener(new OnClickListener(){
                    //perform your action here            
                });

  6. #6
    Membre à l'essai
    Homme Profil pro
    Etudiant
    Inscrit en
    Mars 2014
    Messages
    28
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 30
    Localisation : Suisse

    Informations professionnelles :
    Activité : Etudiant

    Informations forums :
    Inscription : Mars 2014
    Messages : 28
    Points : 21
    Points
    21
    Par défaut
    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
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    package goetschit.Choix;
     
    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.View;
    import android.view.View.*;
    import android.widget.Button;
    import android.widget.Toast;
     
    public class Main extends Activity implements OnClickListener
     
    {
        private static final int INSECTES = 0;  
        private static final int PLANTES = 1;  
        public Button [] listeBoutons = new Button[2];
     
     
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            setContentView(goetschit.Choix.R.layout.accueil);
     
            listeBoutons [INSECTES] = ((Button)this.findViewById(goetschit.Choix.R.id.insectes));
            listeBoutons [PLANTES] = ((Button)this.findViewById(goetschit.Choix.R.id.plantes));
            for (int i = 0; i<listeBoutons.length; i ++){
                listeBoutons[i].setOnClickListener(this);
            }
        }
     
        public void onClick(View view) {
            String msg="Insectes";
            int activite=INSECTES;
     
            switch (view.getId()){
                case goetschit.Choix.R.id.insectes :
                    msg = "Insectes";
                    activite = INSECTES;
                    break;
                case goetschit.Choix.R.id.plantes:
                    msg ="Plantes";
                    activite = PLANTES;
                    break;
     
            }
            Toast msgT = Toast.makeText(this,msg,Toast.LENGTH_SHORT);
            msgT.show();
            creerAcrivite (activite);
        }
     
        public void creerAcrivite(int tmp){
            Intent nvActivite ;
            switch (tmp){
                    case goetschit.Choix.R.id.insectes:
            nvActivite = new Intent (goetschit.Choix.Main.this, goetschit.Choix.Coleoptera.class);
            startActivityForResult(nvActivite, INSECTES);
                        break;
     
           }
        }
     
    }
    j'ai modifié légèrement mon code. J'y apporté les modifications que vous m'avez dit et relu le code correctement mais je ne vois pas d'erreur.

    Merci beaucoup pour votre aide plus haut =) !

  7. #7
    Expert confirmé
    Avatar de Hephaistos007
    Profil pro
    Enseignant Chercheur
    Inscrit en
    Décembre 2004
    Messages
    2 493
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Enseignant Chercheur
    Secteur : Enseignement

    Informations forums :
    Inscription : Décembre 2004
    Messages : 2 493
    Points : 4 166
    Points
    4 166
    Par défaut
    Code java : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
    public void creerAcrivite(int tmp){   //tmp ne peut être que 0 ou 1 vu ton code précédent
            Intent nvActivite ;
            switch (tmp){
                    case INSECTES:  //donc cette valeur doit également être 0 ou 1
            nvActivite = new Intent (goetschit.Choix.Main.this, goetschit.Choix.Coleoptera.class);
            startActivityForResult(nvActivite, INSECTES);
                        break;
     
           }

  8. #8
    Membre à l'essai
    Homme Profil pro
    Etudiant
    Inscrit en
    Mars 2014
    Messages
    28
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 30
    Localisation : Suisse

    Informations professionnelles :
    Activité : Etudiant

    Informations forums :
    Inscription : Mars 2014
    Messages : 28
    Points : 21
    Points
    21
    Par défaut
    Oui mais j'ai fait ça comme ça afin de pouvoir copier/coller mes programmes et juste légèrement les modifier vu que si je fini mon application elle va comporté plein de "page" plus ou moins pareille. Enfin c’était bien ça ta question ?

  9. #9
    Expert confirmé
    Avatar de Hephaistos007
    Profil pro
    Enseignant Chercheur
    Inscrit en
    Décembre 2004
    Messages
    2 493
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Enseignant Chercheur
    Secteur : Enseignement

    Informations forums :
    Inscription : Décembre 2004
    Messages : 2 493
    Points : 4 166
    Points
    4 166
    Par défaut
    Non je parles de
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    case goetschit.Choix.R.id.insectes:
    qui devrait être

  10. #10
    Membre à l'essai
    Homme Profil pro
    Etudiant
    Inscrit en
    Mars 2014
    Messages
    28
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 30
    Localisation : Suisse

    Informations professionnelles :
    Activité : Etudiant

    Informations forums :
    Inscription : Mars 2014
    Messages : 28
    Points : 21
    Points
    21
    Par défaut
    Merci beaucoup ça fonctionne ! =)

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

Discussions similaires

  1. [Windows 7] problème d'impression avec mon application VB6
    Par PrincessKC dans le forum VB 6 et antérieur
    Réponses: 8
    Dernier message: 16/06/2011, 14h36
  2. Problème d'execution avec mon application
    Par jfdmagic dans le forum Installation, Déploiement et Sécurité
    Réponses: 9
    Dernier message: 29/05/2009, 13h23
  3. [MySQL] Affichage de mon livre d'or
    Par emmy99 dans le forum PHP & Base de données
    Réponses: 8
    Dernier message: 24/01/2008, 21h42
  4. [EasyPHP] Problème d'affichage avec mon code PHP
    Par LegioKilt dans le forum EDI, CMS, Outils, Scripts et API
    Réponses: 3
    Dernier message: 24/11/2007, 04h13
  5. Problème d'affichage avec mon BBCode
    Par magic33 dans le forum Langage
    Réponses: 4
    Dernier message: 01/05/2006, 16h30

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