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

Composants graphiques Android Discussion :

Clic sur 2 boutons différents mais même résultat


Sujet :

Composants graphiques Android

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Homme Profil pro
    Webmarketer
    Inscrit en
    Novembre 2012
    Messages
    22
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Webmarketer
    Secteur : Service public

    Informations forums :
    Inscription : Novembre 2012
    Messages : 22
    Par défaut Clic sur 2 boutons différents mais même résultat
    Bonjour,

    J'ai un xml "listes des chapitres" qui contient une liste de chapitre à ouvrir (Chapitre I, chapitre II etc...) j'ai donc un chap1.xml et un chap2.xml

    Malheureusement lorsque je texte mon appli, lorsque je clique sur le bouton Chapitre I, j'ai le même résultat que lorsque je clique sur le bouton chapitre II. Alors que mes xml sont bien différents.... Pouvez -vous m'aider svp ?

    Mon fichier 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
     
    public class RulesActivity extends Activity implements OnClickListener{
     
    	Button ch1Btn;
    	Button ch2Btn;
     
    	@Override
    	public void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.rules);
     
    		//bouton retour
    		Button backBtn = (Button) findViewById(R.id.backBtn);
    		backBtn.setOnClickListener(this);
     
    		//ouvrir chapitre1
    		ch1Btn = (Button) findViewById(R.id.ch1Btn);
    		ch1Btn.setOnClickListener(this);
     
    		//ouvrir chapitre2
    		ch2Btn = (Button) findViewById(R.id.ch2Btn);
    		ch2Btn.setOnClickListener(this);
    	}
     
     
     
    	@Override
    	public void onClick(View arg0) {
     
     
    		ch1Btn : setContentView(R.layout.chap1);
    		ch2Btn : setContentView(R.layout.chap2);
    	}
     
    }


    Mon chap1.xml contient un textView ou se situe mon texte
    idem pour mon chap2.xml

    une partie de mon chap1.xml : est ce que ça viendrait du textView ???

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
        <ScrollView
            android:id="@+id/ScrollView01"
            android:layout_width="fill_parent"
            android:layout_height="300px" >
     
            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="#FFFFFF" />
        </ScrollView>

  2. #2
    Membre Expert
    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
    Par défaut
    Utilises la balise [code] du forum stp.

    Au passage, c'est quoi cette horreur :
    Code java : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    Button backBtn = (Button) findViewById(R.id.backBtn);
    backBtn.setOnClickListener(this);

    Il y a déjà un bouton back physique sur les téléphones Android. Les boutons software c'est sur IPhone...

    Ensuite, je ne vois pas pourquoi tu changes dynamiquement de Layout. Tout les chapitres ont la même structure non ?
    Il vaut mieux mobiliser son intelligence sur des conneries que mobiliser sa connerie sur des choses intelligentes --- devise SHADOKS

    Kit de survie Android : mon guide pour apprendre à programmer sur Android, mon tutoriel sur les web services et enfin l'outil en ligne pour vous faire gagner du temps - N'oubliez pas de consulter la FAQ Android

  3. #3
    Membre averti
    Homme Profil pro
    Webmarketer
    Inscrit en
    Novembre 2012
    Messages
    22
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Webmarketer
    Secteur : Service public

    Informations forums :
    Inscription : Novembre 2012
    Messages : 22
    Par défaut
    Compris pour la balise ^^

    Cette horreur va être enlever ! Utilité limité en effet avec le bouton Back...

    Ensuite, je ne vois pas pourquoi tu changes dynamiquement de Layout. Tout les chapitres ont la même structure non ?]
    Oui, tous les chapitres sont dans des "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
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/background2"
        android:gravity="center_horizontal"
        android:orientation="vertical" >
     
            <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:orientation="horizontal"
            android:paddingBottom="15dip"
            android:paddingTop="15dip" >
     
            <ImageView
                android:id="@+id/logo"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/logo2" />
        </LinearLayout>
     
        <ScrollView
            android:id="@+id/ScrollView01"
            android:layout_width="fill_parent"
            android:layout_height="300px" >
     
            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="MON TEXTE........."
                android:textColor="#FFFFFF" />
        </ScrollView>
     
    </LinearLayout>

    Mais si je le fais pas "dynamiquement, je fais comment ???"

  4. #4
    Membre averti
    Homme Profil pro
    Webmarketer
    Inscrit en
    Novembre 2012
    Messages
    22
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Webmarketer
    Secteur : Service public

    Informations forums :
    Inscription : Novembre 2012
    Messages : 22
    Par défaut
    Je reformule mon problème...

    Je clique sur le bouton "Chapitres" sur ma page d'accueil. J'arrive dans une nouvelle page avec la liste des chapitres. Je clique sur Chapitre I (j'ai le texte du Chapitre II) et je clique sur Chapitre II (j'ai également le texte du Chapitre II).
    Je comprends pas pourquoi....
    J'ai bien mis des android:id différents dans ma page "liste des chapitres...
    Et j'ai bien un chap1.xml et un chap2.xml....

    Le problème doit venir du Java, mais je vois pas quoi mettre à part le OnClickListener....

    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
    public class RulesActivity extends Activity implements OnClickListener{
     
    	Button ch1Btn;
    	Button ch2Btn;
     
    	@Override
    	public void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.listechapitres);
     
    		//ouvrir chapitre1
    		ch1Btn = (Button) findViewById(R.id.ch1Btn);
    		ch1Btn.setOnClickListener(this);
     
    		//ouvrir chapitre2
    		ch2Btn = (Button) findViewById(R.id.ch2Btn);
    		ch2Btn.setOnClickListener(this);
    	}
     
     
     
    	@Override
    	public void onClick(View arg0) {
    		ch1Btn : setContentView(R.layout.chap1);
    		ch2Btn : setContentView(R.layout.chap2);
    	}
     
    }

  5. #5
    Expert confirmé

    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Février 2007
    Messages
    4 253
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Février 2007
    Messages : 4 253
    Billets dans le blog
    3
    Par défaut
    Que penses-tu que fais ce code:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    	@Override
    	public void onClick(View arg0) {
    		ch1Btn : setContentView(R.layout.chap1);
    		ch2Btn : setContentView(R.layout.chap2);
    	}
    (sachant qu'à aucun moment tu n'utilises arg0) ?


    Quant à Hephaistos, il disait... pourquoi changer le layout ?
    N'est ce pas le même layout ?
    Seul le contenu change n'est-ce-pas ?

    Layout = structure
    Contenu = ... hum... contenu ^^

  6. #6
    Membre averti
    Homme Profil pro
    Webmarketer
    Inscrit en
    Novembre 2012
    Messages
    22
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Webmarketer
    Secteur : Service public

    Informations forums :
    Inscription : Novembre 2012
    Messages : 22
    Par défaut
    Bonjour Nicroman,

    merci de ton retour !

    Quant à Hephaistos, il disait... pourquoi changer le layout ?
    N'est ce pas le même layout ?
    Seul le contenu change n'est-ce-pas ?
    Beh... en fait il y a trois xml (listedeschapitres.xml ; chap1.xml, chap2.xml )

    dans listedeschaptres.xml , il y a des layout dont celui qui contient la liste des boutons :
    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
    <LinearLayout
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:orientation="vertical" >
     
                <Button
                    android:id="@+id/ch1Btn"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:text="Chapitre I" />
     
                <Button
                    android:id="@+id/ch2Btn"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:text="Chapitre II" />
    Dans chap1.xml, il y aussi un layout
    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
    65
    66
    67
    68
    69
    70
    71
    72
    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
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/background2"
        android:gravity="center_horizontal"
        android:orientation="vertical" >
     
            <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:orientation="horizontal"
            android:paddingBottom="15dip"
            android:paddingTop="15dip" >
     
            <ImageView
                android:id="@+id/logo"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/logo2" />
        </LinearLayout>
     
        <ScrollView
            android:id="@+id/ScrollView01"
            android:layout_width="fill_parent"
            android:layout_height="300px" >
     
            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="MON TEXTE........."
                android:textColor="#FFFFFF" />
        </ScrollView>
     
    </LinearLayout>
    et dans mon chap2.xml aussi......

    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
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/background2"
        android:gravity="center_horizontal"
        android:orientation="vertical" >
     
            <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:orientation="horizontal"
            android:paddingBottom="15dip"
            android:paddingTop="15dip" >
     
            <ImageView
                android:id="@+id/logo"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/logo2" />
        </LinearLayout>
     
        <ScrollView
            android:id="@+id/ScrollView02"
            android:layout_width="fill_parent"
            android:layout_height="300px" >
     
            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="MON TEXTE 2........"
                android:textColor="#FFFFFF" />
        </ScrollView>
     
    </LinearLayout>
    Lorsque je clique sur Chapitre I ou Chapitre II, j'ai le même résultat qui est le texte du chapitre II,

    Et vu que j'ai aucune erreur dans les logs :S, je comprends pas trop d'où ça peut venir !

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    @Override
    	public void onClick(View arg0) {
    		ch1Btn : setContentView(R.layout.chap1);
    		ch2Btn : setContentView(R.layout.chap2);
    	}
    Pour moi ce code, dis que lorsque je clique sur le bouton ch1Btn, j'ouvre la vue du layout chap1.xml, idem pour chap2

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

Discussions similaires

  1. Réponses: 2
    Dernier message: 14/01/2012, 12h33
  2. Réponses: 3
    Dernier message: 09/07/2008, 01h25
  3. Changer la feuille de style a l aide d un clic sur un bouton
    Par jean_bobi dans le forum Général JavaScript
    Réponses: 3
    Dernier message: 09/11/2005, 08h35
  4. pb sur le premier clic sur un bouton
    Par corwin44 dans le forum Access
    Réponses: 6
    Dernier message: 28/10/2005, 09h51
  5. Gérer les clics sur les boutons
    Par cyberlewis dans le forum Windows
    Réponses: 4
    Dernier message: 08/02/2004, 15h34

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