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

Java Discussion :

Incrémentation Java android


Sujet :

Java

  1. #1
    Nouveau Candidat au Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Avril 2013
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Dordogne (Aquitaine)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Avril 2013
    Messages : 5
    Points : 1
    Points
    1
    Par défaut Incrémentation Java android
    Suite a une application pour android, il a fallu que je fasse une listview et quand on clique dessus il faut incrémenter la quantité mais mon problème est que sa s’incrémente mais toujours au même endroit :
    Je vous donne la partie pour incrémenter :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     listviewperso.setOnItemClickListener(new OnItemClickListener() 
     {
    	@Override
            @SuppressWarnings("unchecked")
             public void onItemClick(AdapterView<?> a, View v, int position, long id) 
    	{
                   HashMap<String, String> map = (HashMap<String, String>)  l
                   listviewperso.getItemAtPosition(position);
            	display = (TextView) findViewById(R.id.display);
                    counter++;
    		display.setText(Integer.toString(counter));
            }
    });
    Pouvez m’orienter sur le problème ?

  2. #2
    Nouveau Candidat au Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Avril 2013
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Dordogne (Aquitaine)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Avril 2013
    Messages : 5
    Points : 1
    Points
    1
    Par défaut
    Voila le code complet :
    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
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    package com.example.application_bar;
     
    import java.util.ArrayList;
    import java.util.HashMap;
    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.ArrayAdapter;
    import android.widget.Button;
    import android.widget.ImageView;
    import android.widget.ListView;
    import android.widget.NumberPicker;
    import android.widget.NumberPicker.Formatter;
    import android.widget.SimpleAdapter;
    import android.widget.TextView;
    import android.app.Activity;
    import android.app.AlertDialog;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.AdapterView;
    import android.widget.ListView;
    import android.widget.SimpleAdapter;
    import android.widget.AdapterView.OnItemClickListener;
     
    public class MainActivityBoisson extends MainActivity
    {
    	private ListView listviewperso;
    	private Button bouton1;
    	private int counter=0;
    	private TextView display;
     
        public void onCreate(Bundle savedInstanceState) //A la creation de la vue
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main2); //Afficher la vue portant le nom "jeu"
     
     
            //Récupération de la listview créée dans le fichier main.xml
            listviewperso = (ListView) findViewById(R.id.listviewperso);
     
            //Création de la ArrayList qui nous permettra de remplire la listView
            ArrayList<HashMap<String, String>> listItem = new ArrayList<HashMap<String, String>>();
     
            //On déclare la HashMap qui contiendra les informations pour un item
            HashMap<String, String> map;
     
            //Création d'une HashMap pour insérer les informations du premier item de notre listView
            map = new HashMap<String, String>();
            //on insère un élément titre que l'on récupérera dans le textView titre créé dans le fichier affichageitem.xml
            map.put("Boisson", "Fanta");
            //on insère un élément description que l'on récupérera dans le textView description créé dans le fichier affichageitem.xml
            map.put("Prix", "2.50€");
            //on insère la référence à l'image (convertit en String car normalement c'est un int) que l'on récupérera dans l'imageView créé dans le fichier affichageitem.xml
            map.put("img", String.valueOf(R.drawable.fanta));
            map.put("display","0");
            //enfin on ajoute cette hashMap dans la arrayList
            listItem.add(map);
     
            map = new HashMap<String, String>();
            map.put("Boisson", "Coca cola");
            map.put("Prix", "2.50€");
            map.put("img", String.valueOf(R.drawable.coca));
            map.put("display","0");
            listItem.add(map);
     
            map = new HashMap<String, String>();
            map.put("Boisson", "Orangina");
            map.put("Prix", "2.50€");
            map.put("img", String.valueOf(R.drawable.orangina));
            map.put("display","0");
            listItem.add(map);
     
            map = new HashMap<String, String>();
            map.put("Boisson", "Demi");
            map.put("Prix", "2€");
            map.put("img", String.valueOf(R.drawable.biere));
            map.put("display","0");
            listItem.add(map);
     
            map = new HashMap<String, String>();
            map.put("Boisson", "Wisky");
            map.put("Prix", "3€");
            map.put("img", String.valueOf(R.drawable.wisky));
            map.put("display","0");
            listItem.add(map);
     
            //Création d'un SimpleAdapter qui se chargera de mettre les items présent dans notre list (listItem) dans la vue affichageitem
            SimpleAdapter mSchedule = new SimpleAdapter (this.getBaseContext(), listItem, R.layout.afficheitem,
                   new String[] {"img", "Boisson", "Prix", "display", "display2"}, new int[] {R.id.img, R.id.Boisson, R.id.Prix, R.id.display});
     
            //On attribut à notre listView l'adapter que l'on vient de créer
            listviewperso.setAdapter(mSchedule);
     
            //Enfin on met un écouteur d'évènement sur notre listView
            listviewperso.setOnItemClickListener(new OnItemClickListener() 
            {
    			@Override
            	@SuppressWarnings("unchecked")
             	public void onItemClick(AdapterView<?> a, View v, int position, long id) 
    			{
            		HashMap<String, String> map = (HashMap<String, String>) listviewperso.getItemAtPosition(position);
            		display = (TextView) findViewById(R.id.display);
                    counter++;
    				display.setText(Integer.toString(counter));
            	}
             });
     
            bouton1 = (Button) findViewById(R.id.button1);
     
        	bouton1.setOnClickListener(new OnClickListener() 
        	{
    			@Override
    			public void onClick(View v) 
    			{
    				Intent i = new Intent(MainActivityBoisson.this,CommandeBoisson.class);
    				startActivity(i);			
    			}
    		});
        }
    }

  3. #3
    Membre du Club
    Homme Profil pro
    Développeur Java
    Inscrit en
    Novembre 2007
    Messages
    37
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Novembre 2007
    Messages : 37
    Points : 56
    Points
    56
    Par défaut
    Bonjour,

    Je ne comprend pas le problème.

    mon problème est que sa s’incrémente mais toujours au même endroit
    C'est en sciant que Léonard De Vinci

  4. #4
    Nouveau Candidat au Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Avril 2013
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Dordogne (Aquitaine)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Avril 2013
    Messages : 5
    Points : 1
    Points
    1
    Par défaut
    J'ai un tableau de listview et j'ai mis un textview qui permet d'incrementer une quantité, mais le probleme c'est que sa s'incremente toujour sur le premier element de ma listView

  5. #5
    Membre régulier
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2011
    Messages
    115
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2011
    Messages : 115
    Points : 106
    Points
    106
    Par défaut
    A vu de ton code la tu incrémente à chaque fois que tu click sur un item de la liste.
    Mais quand tu incrémente ton compteur tu set la nouvelle valeur sur ton TextView display .

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    display.setText(Integer.toString(counter));
    Et non sur l'item que tu a selectionner

  6. #6
    Nouveau Candidat au Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Avril 2013
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Dordogne (Aquitaine)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Avril 2013
    Messages : 5
    Points : 1
    Points
    1
    Par défaut
    Il faut que je modifie quoi, pour que sa marche ?

  7. #7
    Nouveau Candidat au Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Avril 2013
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Dordogne (Aquitaine)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Avril 2013
    Messages : 5
    Points : 1
    Points
    1
    Par défaut
    Aider moi !!! s'il vous plait

Discussions similaires

  1. [Stage] Offre Stage Developpeur C++ / Java / Android
    Par Mobile Tech People dans le forum Demandes
    Réponses: 0
    Dernier message: 17/08/2010, 11h10

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