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 récupération variable


Sujet :

Android

  1. #1
    Membre du Club
    Homme Profil pro
    Administrateur Télécoms
    Inscrit en
    Décembre 2010
    Messages
    67
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Administrateur Télécoms
    Secteur : Service public

    Informations forums :
    Inscription : Décembre 2010
    Messages : 67
    Points : 52
    Points
    52
    Par défaut Problème récupération variable
    Bonjour la communauté,

    voila mon mon problème j ai récupéré un script qui fonctionne bien mais voila : j ai trois classe la premiere la classe Book qui me permet de recuperer mes données, apres j ai un un Userlistadapter pour mettre en forme puis une classe ou je dois récupéré la donnée en fonction du clic et la pas d affichage et aucun problème l application se lance bien. donc je joins le code des trois classe avec les commentaires si quelqu un peu me faire avancer merci car malgré mes cours de base en java je rame grave. merci par avance.

    la classe Book:
    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
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
     
    public class Book implements Comparable<Book> {
     
     
     
    	public  String produits;
     
    	public String pci;
     
    	public String pvs;
     
    	private String massevolumique;
     
    	private String densiteair;
     
    	private String masse;
     
    	private String facteurrtnt;
     
    	private String liste;
     
     
     
    	public Book() {
    		// TODO Auto-generated constructor stub
    	}
     
    	public Book(String produits, String pci, String pvs, String massevolumique,
    			String densiteair, String masse, String facteurrtnt, String liste) {
    		super();
    		this.produits = produits;
    		this.pci = pci;
    		this.pvs = pvs;
    		this.massevolumique = massevolumique;
    		this.densiteair = densiteair;
    		this.masse = masse;
    		this.facteurrtnt = facteurrtnt;
    		this.liste = liste;
    	}
     
    	/**
             * @return le produit
             */
    	public   String getProduits() {
    		return produits;
    	}
     
    	/**
             * @param title
             *            the title to set
             */
    	public void setTitle(String produits) {
    		this.produits = produits;
    	}
     
    	/**
             * @return the author
             */
    	public String getPci() {
    		return pci;
    	}
     
    	/**
             * @param author
             *            the author to set
             */
    	public void setPci(String pci) {
    		this.pci = pci;
    	}
     
    	/**
             * @return the year
             */
    	public String getPvs() {
    		return pvs;
    	}
     
    	/**
             * @param year
             *            the year to set
             */
    	public void setPvs(String pvs) {
    		this.pvs = pvs;
    	}
     
    	/**
             * @return the country
             */
    	public String getMassevolumique() {
    		return massevolumique;
    	}
     
    	/**
             * @param country
             *            the country to set
             */
    	public void setMassevolumique(String massevolumique) {
    		this.massevolumique = massevolumique;
    	}
     
    	/**
             * @return the language
             */
    	public String getDensiteair() {
    		return densiteair;
    	}
     
    	/**
             * @param language
             *            the language to set
             */
    	public void setDensiteair(String densiteair) {
    		this.densiteair = densiteair;
    	}
     
    	/**
             * @return la masse
             */
    	public String getMasse() {
    		return masse;
    	}
     
    	/**
             * @param language
             *            the language to set
             */
    	public void setMasse(String masse) {
    		this.masse = masse;
    	}
     
    	public String getFacteurtnt() {
    		return facteurrtnt;
    	}
     
    	public void setFacteurtnt(String facteurrtnt) {
    		this.facteurrtnt = facteurrtnt;
    	}
     
     
     
     
     
    	public String getListe() {
    		return liste;
    	}
     
    	/**
             * @param liste
             *            the liste to set
             */
    	public void setListe(String liste) {
    		this.liste = liste;
    	}
     
    	@Override
    	public int compareTo(Book book) {
    		return this.getProduits().compareTo(book.getProduits());
    	}	
    }

    la classe Userlistadapter

    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
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    
    
    public class UserListAdapter extends BaseAdapter implements OnClickListener  {
    	
    	private static final String TAG = UserListAdapter.class.getName();
    	private Activity activity;
    	public Vector<Book> items;
    	private Context mContext;
    	public static CharSequence affichageProduits;
    	
    	
    	ImageButton retour;
    
    	
    	
    	
    	
    	public UserListAdapter(Activity activity, Vector<Book> items) {
    		Log.i(TAG, TAG);
    		this.activity = activity;
    		this.items = items;
    	
    		
    	}
    
    	@SuppressLint("ResourceAsColor")
    	public View getView(final int position, View convertView, ViewGroup parent) {
    		
    			
    		ViewHolder holder;
    
    		if (convertView == null) {
    			
    			
    			
    			LayoutInflater inflater = activity.getLayoutInflater();
    			convertView = inflater.inflate(R.layout.listrow_user, null);
    			
    			holder = new ViewHolder();
    			
    			holder.name = (TextView) convertView.findViewById(R.id.nameTV);
    			holder.headingLL = (LinearLayout) convertView
    					.findViewById(R.id.headingLL);
    			holder.headingTV = (TextView) convertView
    					.findViewById(R.id.headingTV);
    			holder.nameLL = (LinearLayout) convertView
    					.findViewById(R.id.nameLL);
    
    			convertView.setTag(holder);
    
    		} else {
    			holder = (ViewHolder) convertView.getTag();
    		}
    
    		if (position < items.size()) {
    
    			final Book book = items.get(position);
    			if (book != null && (book.getProduits().length() == 1)) {
    				holder.nameLL.setVisibility(View.GONE);
    				holder.headingLL.setVisibility(View.VISIBLE);
    				holder.headingTV.setText(book.getProduits());
    				holder.headingLL
    						.setBackgroundColor(android.R.color.transparent);
    			} else {
    				holder.nameLL.setVisibility(View.VISIBLE);
    				holder.headingLL.setVisibility(View.GONE);
    				holder.name.setText(book.getProduits());
    
    				View ll = (LinearLayout) holder.name.getParent();
    				ll.setFocusable(true);
    				ll.setSelected(true);
    				ll.setOnClickListener(new OnClickListener() {
    				
    					
    
    					public void onClick(View v) {
    						/* action sur le clic */
    					
    						if (book.getListe().equals("A") & Intervention.resultatclic==1 ) {
    							
    							Toast.makeText(activity.getApplicationContext(),
    									book.getProduits(),
    									Toast.LENGTH_SHORT).show();
    							
    							Intent menuIntent = new Intent(activity,Calculbleve.class);
    							activity.startActivity(menuIntent);
    							finish();
    						}	
    							
    						else if (book.getListe().equals("A") & Intervention.resultatclic==2 ){
    							
    							Toast.makeText(activity.getApplicationContext(),
    									book.getProduits(),
    									Toast.LENGTH_SHORT).show();
    		
    							
    							Intent menuIntent = new Intent(activity,Intervention.class);
    							activity.startActivity(menuIntent);
    							finish();
    						}
    							
    						if (book.getListe().equals("B") & Intervention.resultatclic==1) {
    							
    							Toast.makeText(activity.getApplicationContext(),
    									book.getProduits(),
    									Toast.LENGTH_SHORT).show();  Ici quand je clic le produits je dois recuperer le nom pour l afficher dans ma troisieme classe
    					
    							Intent menuIntent = new Intent(activity,Calculbleve.class);
    							activity.startActivity(menuIntent);
    							finish();
    						}
    						 else if (book.getListe().equals("B") & Intervention.resultatclic==2) {
    								
    								Toast.makeText(activity.getApplicationContext(),
    										book.getProduits(),
    										Toast.LENGTH_SHORT).show();
    								Intent menuIntent = new Intent(activity,Intervention.class);
    								activity.startActivity(menuIntent);
    								finish();
    							}	
    						 if (book.getListe().equals("C")) {
    						
    							Toast.makeText(activity.getApplicationContext(),
    									book.getProduits(),
    									Toast.LENGTH_SHORT).show();
    						
    							
    
    						}
    
    					}
    
    					private Context getApplication() {
    						// TODO Auto-generated method stub
    						return null;
    					}
    
    					private Context getBaseContext() {
    						// TODO Auto-generated method stub
    						return null;
    					}
    
    					private void startActivity(Intent menuIntent) {
    						// TODO Auto-generated method stub
    
    					}
    				});
    			}
    		}
    
    		return convertView;
    	}
    
    	
    
    
    
    	
    	protected void finish() {
    		// TODO Auto-generated method stub
    
    	}
    
    	private static class ViewHolder {
    		TextView name, headingTV;
    		LinearLayout nameLL, headingLL;
    	
    	}
    
    	@Override
    	public int getCount() {
    		return items.size();
    	}
    
    	@Override
    	public Object getItem(int position) {
    		return items.get(position);
    	}
    
    	@Override
    	public long getItemId(int position) {
    		return position;
    	}
    	@Override
    	public void onClick(View v) {
    		// TODO Auto-generated method stub
    		
    	}
    	
    
    	
    	
    }


    et enfin ma classe calcul ou j ai le probleme

    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
    public class Calculbleve extends Activity implements OnClickListener{
    	
    	Button bleve;
    	ImageButton retour;
    	TextView titre;
    	
    
    	public void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.calculbleve);
    		
    		LinearLayout monInclude = (LinearLayout) findViewById(R.id.include);
            retour = (ImageButton) monInclude.findViewById(R.id.imageButtonRetour);
    		retour.setOnClickListener(this);// ecoute du bouton sur un clic
    		
    		titre = (TextView)monInclude.findViewById(R.id.titre);
    		titre.setText(Book.getProduits()); ici le pb je suis oblige de transformer en static et je ne peux pas sinon ca pose un pb sur mon adapter et affichage.Si je  cree une methode   complementaire dans Book cela ne m affiche rien.
    
    }
    
    @Override
    	public void onClick(View v) {
    		// TODO Auto-generated method stub
    		if (v==retour){
    			Intent retourIntent = new Intent (this, IndexTableActivityAB.class);
    			startActivity(retourIntent);
    			finish();
    		}
    	}	
    	}
    Voila les infos sont marquées en rouge dans les class
    Le toast est simplement la pour vérifier pendant mon développement le produit cliquer et voir que ca fonctionne et que mon clic démarre bien sur ma nouvelle classe

    merci encore pour vos infos et votre aide


    cordialement Eric

  2. #2
    Membre habitué
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Octobre 2011
    Messages
    216
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Octobre 2011
    Messages : 216
    Points : 139
    Points
    139
    Par défaut
    salut,

    je dirais peut être qu'il faut instancier ta classe Book dans ta classe calcul.

    créer un objet Book dans ta classe calcul afin de pouvoir accéder aux méthodes non statiques.

    je pense que si tu crée une méthode complémentaire dans Book (je pense que cela veut dire une classe static dans Book) cela ne t'affiche rien, normal, tu n'a pas donnée de valeur a ta variable produits.

    voilou. tiens au jus.

  3. #3
    Modérateur
    Avatar de Hizin
    Homme Profil pro
    Développeur mobile
    Inscrit en
    Février 2010
    Messages
    2 180
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France

    Informations professionnelles :
    Activité : Développeur mobile

    Informations forums :
    Inscription : Février 2010
    Messages : 2 180
    Points : 5 072
    Points
    5 072
    Par défaut
    Non.

    Il faut que tu passes l'objet Book sélectionné à l'autre Activité. Ou seulement le nom de celui-ci, vu que tu n'as pas l'air d'utiliser autre chose.

    Pour faire ceci, passe par le système de Bundle des Intent, via Intent#putExtra

    Doc du Bundle : http://developer.android.com/referen...os/Bundle.html

    De manière générale, je te suggères de te renseigner sur la communication inter-activité.
    C'est Android, PAS Androïd, ou Androïde didiou !
    Le premier est un OS, le second est la mauvaise orthographe du troisième, un mot français désignant un robot à forme humaine.

    Membre du comité contre la phrase "ça marche PAS" en titre et/ou explication de problème.

    N'oubliez pas de consulter les FAQ Android et les cours et tutoriels Android

  4. #4
    Membre du Club
    Homme Profil pro
    Administrateur Télécoms
    Inscrit en
    Décembre 2010
    Messages
    67
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Administrateur Télécoms
    Secteur : Service public

    Informations forums :
    Inscription : Décembre 2010
    Messages : 67
    Points : 52
    Points
    52
    Par défaut
    merci pour vos réponses je regarde je vous tiens au courant.....

  5. #5
    Membre du Club
    Homme Profil pro
    Administrateur Télécoms
    Inscrit en
    Décembre 2010
    Messages
    67
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Administrateur Télécoms
    Secteur : Service public

    Informations forums :
    Inscription : Décembre 2010
    Messages : 67
    Points : 52
    Points
    52
    Par défaut
    bonjour grâce a votre aide j a résolu mon problème,

    dans ma première activité j ai mis le code suivant pour appeler l intent:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    Intent calculbleve = new Intent(activity,Calculbleve.class);
    							calculbleve.putExtra("produits",book.getProduits());
    							activity.startActivityForResult(calculbleve,CODE_RETOUR);
    							finish();
    et dans l activité que j appelle voici le code:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    Bundle extras = getIntent().getExtras(); 
    		String resultproduits = extras.getString( "produits" );
     
    		titre.setText(resultproduits);
    avant de clôturer ce message je voudrais savoir si je peux mettre plusieurs putExtra a la suite avec un seul code retour exemple si dessous:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    calculbleve.putExtra("produits",book.getProduits());
    calculbleve.putExtra("nom",book.getProduits());
    calculbleve.putExtra("poids",book.getProduits());
    activity.startActivityForResult(calculbleve,CODE_RETOUR);
    							finish();
    comme cela ca me permettrait d afficher ce que je veux en fonction de mes besoin et du clic.


    cordialement Eric

  6. #6
    Modérateur
    Avatar de Hizin
    Homme Profil pro
    Développeur mobile
    Inscrit en
    Février 2010
    Messages
    2 180
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France

    Informations professionnelles :
    Activité : Développeur mobile

    Informations forums :
    Inscription : Février 2010
    Messages : 2 180
    Points : 5 072
    Points
    5 072
    Par défaut
    Tu peux mettre autant d'extra que tu le désirs. Ceux-ci se comportent comme une map clé<->valeur.
    Du moment que tu n'écrases pas les couples...
    C'est Android, PAS Androïd, ou Androïde didiou !
    Le premier est un OS, le second est la mauvaise orthographe du troisième, un mot français désignant un robot à forme humaine.

    Membre du comité contre la phrase "ça marche PAS" en titre et/ou explication de problème.

    N'oubliez pas de consulter les FAQ Android et les cours et tutoriels Android

  7. #7
    Membre du Club
    Homme Profil pro
    Administrateur Télécoms
    Inscrit en
    Décembre 2010
    Messages
    67
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Administrateur Télécoms
    Secteur : Service public

    Informations forums :
    Inscription : Décembre 2010
    Messages : 67
    Points : 52
    Points
    52
    Par défaut
    Merci pour la réponse cela viens confirmer l'essai que j ai effectué.


    Cordialement

    Bonnes fêtes de Noël et de fin d'années
    et merci pour l'aide

    je clôture le sujet


    Eric

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

Discussions similaires

  1. [MySQL] probléme récupération variable
    Par Jérém08 dans le forum PHP & Base de données
    Réponses: 8
    Dernier message: 30/10/2009, 15h58
  2. [Smarty] Problème récupération variable dans un for
    Par slaxsystem dans le forum Bibliothèques et frameworks
    Réponses: 4
    Dernier message: 02/05/2007, 17h10
  3. Réponses: 29
    Dernier message: 02/04/2007, 09h42
  4. Problèmes récupération variable
    Par bouchette63 dans le forum Général JavaScript
    Réponses: 8
    Dernier message: 15/06/2006, 10h44
  5. [MySQL] Problème récupération variable pour requête SQL !!
    Par mLk92 dans le forum PHP & Base de données
    Réponses: 3
    Dernier message: 01/06/2006, 16h08

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