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 :

IF EditText vide


Sujet :

Android

  1. #1
    Futur Membre du Club
    Homme Profil pro
    Inscrit en
    Janvier 2013
    Messages
    18
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2013
    Messages : 18
    Points : 8
    Points
    8
    Par défaut IF EditText vide
    Bonjour,

    Je fais une simple activité de calcul de tips (pourboires) dont voici le code et ça marche plutôt bien pour l'instant.

    Tips.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
    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
    package com.example.monappli;
     
    import android.app.Activity;
    import android.os.Bundle;
    import android.text.Editable;
    import android.text.TextUtils;
    import android.text.TextWatcher;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.SeekBar;
    import android.widget.TextView;
    import android.widget.Toast;
     
    public class Tips extends Activity implements SeekBar.OnSeekBarChangeListener {
     
      private final String defaut = "Vous devez cliquer"; // La chaîne de caractères par défaut  
      private final String defautpersonne = "1";
     
      Button envoyer = null;
      Button raz = null;	
      SeekBar mSeekBar;
      TextView ResMontantTip = null;  
      EditText EditMontantAddition;
      TextView mProgressText;
      TextView Niveau;
      EditText EditNombrePersonne;
      TextView ResTotal;
      TextView ResTotalPersonne;
     
      @Override
      public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tips);
     
        // Récuperation des vues
        envoyer = (Button)findViewById(R.id.calcul);    	
        raz = (Button)findViewById(R.id.raz);
        mSeekBar = (SeekBar)findViewById(R.id.seek);     
        mProgressText = (TextView)findViewById(R.id.progress);
        Niveau = (TextView)findViewById(R.id.Niveau);
        ResMontantTip = (TextView)findViewById(R.id.ResMontantTip);    
        ResTotal = (TextView)findViewById(R.id.ResTotal);
        ResTotalPersonne = (TextView)findViewById(R.id.ResTotalPersonne);
        EditMontantAddition = (EditText)findViewById(R.id.EditMontantAddition);
        EditNombrePersonne = (EditText)findViewById(R.id.EditNombrePersonne);    
     
        // Attribution des listener adaptés aux vues
        EditNombrePersonne.setText(""  + String.valueOf(defautpersonne)); 
        mSeekBar.setOnSeekBarChangeListener(this);
        mSeekBar.setProgress(15);
        Niveau.addTextChangedListener(textWatcher);
        envoyer.setOnClickListener(envoyerListener);
        raz.setOnClickListener(razListener);
        EditMontantAddition.addTextChangedListener(textWatcher);
        EditNombrePersonne.addTextChangedListener(textWatcher);
        mProgressText.addTextChangedListener(textWatcher); 
      }
     
    	public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch) {
    	  mProgressText.setText(progress + 10+ " " + getString(R.string.pourcentage));
    	  mProgressText.setText(Integer.toString(progress));	
     
            if(progress<=9) {
            	Niveau.setText("" + getString(R.string.Mauvais));
            }       
            else if(progress>=10 && progress<=14)
            {        
            	Niveau.setText(getString(R.string.PasMal));
            }
            else if(progress>=15 && progress<=17)
            {
            	Niveau.setText(getString(R.string.Bien));
            }
            else if(progress>=18 && progress<=20)
            {
            	Niveau.setText(getString(R.string.Genial));    
            }
    	}
    	public void onStartTrackingTouch(SeekBar seekBar) {}	 
    	public void onStopTrackingTouch(SeekBar seekBar) {}	  
     
      private TextWatcher textWatcher = new TextWatcher() {
     
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
          ResMontantTip.setText(defaut);
        }    
     
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count,
          int after) { }
     
        @Override
        public void afterTextChanged(Editable s) { }
      };
     
      // Bouton Calculer
      private OnClickListener envoyerListener = new OnClickListener() {
        @Override
        public void onClick(View v) {
     
            String montant = EditMontantAddition.getText().toString(); //Récupèration du montant de l'addition        
            String personne = EditNombrePersonne.getText().toString(); // Récupèration du nombre de personnes 
            String tip = mProgressText.getText().toString(); // Récupèration du montant du tip
     
            float Vmontant = Float.valueOf(montant);
            float Vpersonne = Float.valueOf(personne);
            float Pourcentip = Float.valueOf(tip);              
     
           if(Vmontant == 0) // REGLER LE BUG DES CHAMPS VIDES!!
            //if (Vmontant.equals(""))
              Toast.makeText(Tips.this, "Pas cohérent", Toast.LENGTH_SHORT).show();
            else {        	
     
            	float Vtip = Vmontant * Pourcentip / 100;        	
            	float total = Vmontant + Vtip;
            	float totalp = total / Vpersonne;
     
            	ResMontantTip.setText("" + String.valueOf(Vtip)); 
            	ResTotal.setText("" + String.valueOf(total));
            	ResTotalPersonne.setText("" + String.valueOf(totalp));
            }
        }
      };
     
      // Listener RAZ
      private OnClickListener razListener = new OnClickListener() {
        @Override
        public void onClick(View v) {
        	EditMontantAddition.getText().clear();
        	EditNombrePersonne.getText().clear();
        }
      };
      };
    Le tips.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
    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
    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#000000"
        tools:context=".MainActivity" >
     
    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        style="@style/SunsetTheme"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
     
        <TextView
            android:id="@+id/MontantAddition"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:gravity="center"
            android:text="@string/TipsMontantAddition"
            android:textColor="@color/TextBlack"
            android:textStyle="bold" />
     
        <EditText
            android:id="@+id/EditMontantAddition"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/MontantAddition"
            android:ems="10"
            android:hint="@string/TipsMontantAddition"
            android:inputType="numberDecimal"
            android:textColor="@color/TextBrown"
            android:textColorHint="@color/Grey"
            android:textSize="@dimen/titres" />
     
        <TextView
            android:id="@+id/NombrePersonne"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/EditMontantAddition"
            android:gravity="center"
            android:text="@string/TipsNombre"
            android:textColor="@color/TextBlack"
            android:textStyle="bold" />
     
        <EditText
            android:id="@+id/EditNombrePersonne"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/NombrePersonne"
            android:ems="10"
            android:hint="@string/TipsNombre"
            android:inputType="numberDecimal"
            android:textColor="@color/TextBrown"
            android:textColorHint="@color/Grey"
            android:textSize="@dimen/titres" />
     
        <TextView
            android:id="@+id/MontantTip"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/seek"
            android:gravity="center"
            android:text="@string/TipsMontantTip"
            android:textColor="@color/TextBlack"
            android:textSize="@dimen/textSize"
            android:textStyle="bold" />
     
        <TextView
            android:id="@+id/Pourcentage"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/EditNombrePersonne"
            android:gravity="center"
            android:text="@string/TipsPourcentage"
            android:textColor="@color/TextBlack"
            android:textStyle="bold" />
     
        <SeekBar
            android:id="@+id/seek"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/Pourcentage"
            android:layout_toLeftOf="@+id/calcul"
            android:max="20"
            android:progress="1" />
     
        <TextView
            android:id="@+id/progress"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/MontantTip"
            android:text="@string/pourcentage"
            android:textSize="@dimen/titres" />
     
        <TextView
            android:id="@+id/ResMontantTip"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@id/progress"
            android:text="@string/Dollar"
            android:textSize="@dimen/titres" />
     
        <TextView
            android:id="@+id/TotalPersonne"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/ResMontantTip"
            android:gravity="center"
            android:text="@string/TipsTotalPersonne"
            android:textColor="@color/TextBlack"
            android:textStyle="bold" />
     
        <TextView
            android:id="@+id/ResTotalPersonne"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/TotalPersonne"
            android:text="@string/Dollar"
            android:textSize="@dimen/titres" />
     
        <TextView
            android:id="@+id/Total"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/ResTotalPersonne"
            android:gravity="center"
            android:text="@string/TipsTotal"
            android:textColor="@color/TextBlack"
            android:textSize="@dimen/textSize"
            android:textStyle="bold" />
     
        <TextView
            android:id="@+id/ResTotal"
            android:layout_width="fill_parent"
            android:layout_height="50dp"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/Total"
            android:text="@string/Dollar"
            android:textSize="@dimen/titres" />
     
        <Button
            android:id="@+id/raz"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:text="@string/RAZ" />
     
        <Button
            android:id="@+id/calcul"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:text="@string/Calculer" />
     
        <TextView
            android:id="@+id/Niveau"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/seek"
            android:layout_alignParentRight="true"
            android:layout_alignTop="@+id/seek"
            android:layout_toRightOf="@+id/seek"
            android:ems="10"
            android:text="@string/Niveau"
            android:textSize="@dimen/textSize" />
     
     
    </RelativeLayout>
     
    </FrameLayout>
    Seulement j'ai un léger soucis, lorsque je calcul mon résultat avec des champs vides EditMontantAddition et EditNombrePersonne, l'appli crash.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    01-20 22:42:48.310: E/AndroidRuntime(5429): java.lang.NumberFormatException: Invalid float: ""

    Au niveau de la ligne 112, j'ai essayé le IF avec
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    if(EditMontantAddition.getText().length() = 0
    ou avec
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    if((EditMontantAddition != null) && (!TextUtils.isEmpty(EditMontantAddition.getText().toString()))){
    mais je n'y arrive pas.

    1) Comment puis-je simplement tester si mes champs sont vides et afficher mon toast dans ce cas?

    Une autre question au passage, je souhaiterai que ma seekbar aille de 10 à 20 (donc j'arrive à l'afficher ainsi avec le ligne 62

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    mProgressText.setText(progress + 10+ " " + getString(R.string.pourcentage));
    mProgressText devient donc un string (exemple "15%" et je ne peux plus la manipuler en tant que float pour mes calculs suivants.

    2) Comment puis-je afficher mon texte avec le string, et en même temps, affecter le float à une variable pour que je puisse le récupérer plus loin (lignes 102 à 123)

    Merci d'avance

  2. #2
    Expert éminent

    Avatar de Feanorin
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    4 589
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 4 589
    Points : 9 149
    Points
    9 149
    Par défaut
    Bonjour,

    Déjà pour tester ta longueur c'est

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    if(EditMontantAddition.getText().length() == 0)
    et non

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    if(EditMontantAddition.getText().length() = 0)
    Ensuite essaye de gérer les cas nominaux après insère un try catch autour de tes valueOf pour gérer les autres cas.
    Responsable Android de Developpez.com (Twitter et Facebook)
    Besoin d"un article/tutoriel/cours sur Android, consulter la page cours
    N'hésitez pas à consulter la FAQ Android et à poser vos questions sur les forums d'entraide mobile d'Android.

  3. #3
    Futur Membre du Club
    Homme Profil pro
    Inscrit en
    Janvier 2013
    Messages
    18
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2013
    Messages : 18
    Points : 8
    Points
    8
    Par défaut
    Merci, effectivement, je m'y été mal pris.

    J'ai revu le principe de mon activité, je souhaite maintenant lancer les calculs automatiquement lors des changements sur les edit text et ma progressbar.

    Comment puis-je appeler la fonction de mon bouton "envoyerListener" (qui ne sera plus un bouton mais une simple fonction) à chaque changement dans mes edit text et autres?

  4. #4
    Expert éminent

    Avatar de Feanorin
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    4 589
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 4 589
    Points : 9 149
    Points
    9 149
    Par défaut
    Bonjour,

    je ne sais pas si j'ai bien compris la question , mais tu pourras exécuter ta fonction à partir de tes textWatcher par exemple. Après a toi à partir de ces watchers de savoir quoi en faire :/.
    Responsable Android de Developpez.com (Twitter et Facebook)
    Besoin d"un article/tutoriel/cours sur Android, consulter la page cours
    N'hésitez pas à consulter la FAQ Android et à poser vos questions sur les forums d'entraide mobile d'Android.

  5. #5
    Futur Membre du Club
    Homme Profil pro
    Inscrit en
    Janvier 2013
    Messages
    18
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2013
    Messages : 18
    Points : 8
    Points
    8
    Par défaut
    Bonsoir,

    Tu avais bien compris ma question et je comprend maintenant que ta réponse était logique, le TextWatcher!
    Donc ça fonctionne très bien, j'ai viré le bouton de calcul et j'ai mis tout mon traitement dans le Watcher, j'ai résolu mon problème de champ vide et j'ai encore appris plein de choses.

    Voici le code pour les curieux

    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
    import android.app.Activity;
    import android.os.Bundle;
    import android.text.Editable;
    import android.text.TextWatcher;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.RatingBar;
    import android.widget.SeekBar;
    import android.widget.TextView;
    import android.widget.Toast;
    import android.widget.RatingBar.OnRatingBarChangeListener;
     
    public class Tips extends Activity  {  
    	private RatingBar ratingBar;
    	private TextView txtRatingValue;
     
      TextView ResMontantTip = null;  
      EditText EditMontantAddition;
      TextView mProgressText;
      TextView Niveau;
      EditText EditNombrePersonne;
      TextView ResTotal;
      TextView ResTotalPersonne;
     
      @Override
      public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tips);
        addListenerOnRatingBar();
        // Récuperation des vues 
        mProgressText = (TextView)findViewById(R.id.progress);
        Niveau = (TextView)findViewById(R.id.Niveau);
        ResMontantTip = (TextView)findViewById(R.id.ResMontantTip);    
        ResTotal = (TextView)findViewById(R.id.ResTotal);
        ResTotalPersonne = (TextView)findViewById(R.id.ResTotalPersonne);
        EditMontantAddition = (EditText)findViewById(R.id.EditMontantAddition);
        EditNombrePersonne = (EditText)findViewById(R.id.EditNombrePersonne);    
     
        // Attribution des listener adaptés aux vues
        EditMontantAddition.setText("100"); 
        EditNombrePersonne.setText("1"); 
        txtRatingValue.setText("15");
        Niveau.setText(getString(R.string.Bien));
        txtRatingValue.addTextChangedListener(textWatcher);
        EditMontantAddition.addTextChangedListener(textWatcher);
        EditNombrePersonne.addTextChangedListener(textWatcher);
      }
     
    	public void onStartTrackingTouch(SeekBar seekBar) {}	 
    	public void onStopTrackingTouch(SeekBar seekBar) {}	
    	public void addListenerOnRatingBar() {
    		ratingBar = (RatingBar) findViewById(R.id.ratingBar);
    		txtRatingValue = (TextView) findViewById(R.id.txtRatingValue);
    		ratingBar.setStepSize((float) 1); // a 0.25 sur 5 etoiles, echelle sur 20
            ratingBar.setRating((float) 4); 
    		ratingBar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
    			public void onRatingChanged(RatingBar ratingBar, float rating, 
    					boolean fromUser) {				
    					rating = (rating * 5);
    				   if(rating == 5) {Niveau.setText(getString(R.string.Mauvais));txtRatingValue.setText("5");}       
    			        else if(rating == 10){Niveau.setText(getString(R.string.PasMal));txtRatingValue.setText("10");}
    			        else if(rating == 15){Niveau.setText(getString(R.string.Bien));txtRatingValue.setText("15");}
    			        else if(rating == 20){Niveau.setText(getString(R.string.Genial)); txtRatingValue.setText("20");}
    			        else if(rating == 25){Niveau.setText(getString(R.string.Excellent)); txtRatingValue.setText("25");
    			       }				    				   
    			}
    		});
    	}
     
    	private TextWatcher textWatcher = new TextWatcher() {
    	    @Override
    	    public void onTextChanged(CharSequence s, int start, int before, int count) {
     
    	    if(EditMontantAddition.length()==0 || EditNombrePersonne.length()==0)
    	       Toast.makeText(Tips.this, (getString(R.string.ErreurChamps)), Toast.LENGTH_SHORT).show(); 
    	  	   else {
    	  	        ResMontantTip.setText ("" + String.valueOf(Float.valueOf(EditMontantAddition.getText().toString()) * Float.valueOf(txtRatingValue.getText().toString()) / 100)); 
    	  	        ResTotal.setText ("" + String.valueOf(Float.valueOf(EditMontantAddition.getText().toString()) + (Float.valueOf(EditMontantAddition.getText().toString()) * Float.valueOf(txtRatingValue.getText().toString()) / 100)));
    	  	        ResTotalPersonne.setText("" + String.valueOf(Float.valueOf(EditMontantAddition.getText().toString()) + (Float.valueOf(EditMontantAddition.getText().toString()) * Float.valueOf(txtRatingValue.getText().toString()) / 100) / Float.valueOf(EditNombrePersonne.getText().toString())));  
    	      }
    	    }	
    	    @Override
    	    public void beforeTextChanged(CharSequence s, int start, int count, int after) { }  
    	    @Override
    	    public void afterTextChanged(Editable s) { }
    	  };
      };
    Si vous trouvez moyen d'optimiser le code d'avantage, je vous écoute

    Une dernière question pour la forme, comment, à l'ouverture de l'activité, puis-je directement lancer mon calcul par le TextWatcher avec les valeurs par défaut (100$, 1 personne et 15% de tips) sans faire un setText sur les champs de résultats? (100 + (100 * (15 /100)) = 115$)

    Merci!

  6. #6
    Expert éminent

    Avatar de Feanorin
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    4 589
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 4 589
    Points : 9 149
    Points
    9 149
    Par défaut
    Bonjour,

    Une dernière question pour la forme, comment, à l'ouverture de l'activité, puis-je directement lancer mon calcul par le TextWatcher avec les valeurs par défaut (100$, 1 personne et 15% de tips) sans faire un setText sur les champs de résultats? (100 + (100 * (15 /100)) = 115$)
    euh si tu ne fais pas un setText tu auras quoi dans tes EditText comme valeur par défault ?

    Ensuite si tu veux des données par défault il te suffit simplement que lorsque le textWatcher est appelé si les données trouvé ne te plaise pas utilise alors des valeurs par défaut.

    Maintenant à toi de déterminer quand et comment pévenir l'utilisateur de l'utilisation de ces données
    Responsable Android de Developpez.com (Twitter et Facebook)
    Besoin d"un article/tutoriel/cours sur Android, consulter la page cours
    N'hésitez pas à consulter la FAQ Android et à poser vos questions sur les forums d'entraide mobile d'Android.

  7. #7
    Futur Membre du Club
    Homme Profil pro
    Inscrit en
    Janvier 2013
    Messages
    18
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2013
    Messages : 18
    Points : 8
    Points
    8
    Par défaut
    Bonjour,

    euh si tu ne fais pas un setText tu auras quoi dans tes EditText comme valeur par défault ?

    Actuellement, j'ai 3 valeurs par défaut à l'ouverture de l'activité:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    EditMontantAddition.setText("100"); 
    EditNombrePersonne.setText("1"); 
    txtRatingValue.setText("15");
    En clair:

    • le montant de l'addition
    • le nombre de personnes
    • le pourcentage du tip


    pour ne pas avoir à rajouter des valeurs par défaut qui seraient ni plus ni moins que le calcul des 3 setText ci dessus, je voudrais pouvoir directement lancer mon textwatcher avec ces dernières.

    J'ai pas vraiment saisi les 2 dernières phrases de ton post

    Bon, quoiqu'il en soit, c'est loin d'être insurmontable. Je peut simplement mettre des valeurs par défaut pour mes résultats.

  8. #8
    Expert éminent

    Avatar de Feanorin
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    4 589
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 4 589
    Points : 9 149
    Points
    9 149
    Par défaut
    En fait, si j'ai bien compris, tu veux des valeurs par défaut pour tes calculs mais qui ne seront pas affiché sur tes TextView. c'est ça ?

    Pour cela je te proposais depuis ton TextWatcher, d'utiliser des valeurs par défaut lorsque les valeurs présentes dans tes TextView ne te convenait pas.

    Si j'ai pas compris la question et que tu voulais tout simplement ne pas faire le setText, alors depuis ton xml attribut une valeur par défaut sur tes TextView

    Responsable Android de Developpez.com (Twitter et Facebook)
    Besoin d"un article/tutoriel/cours sur Android, consulter la page cours
    N'hésitez pas à consulter la FAQ Android et à poser vos questions sur les forums d'entraide mobile d'Android.

  9. #9
    Futur Membre du Club
    Homme Profil pro
    Inscrit en
    Janvier 2013
    Messages
    18
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2013
    Messages : 18
    Points : 8
    Points
    8
    Par défaut
    Je pense que je m'était mal exprimé. Je veux effectivement que mes résultats soient issus du calcul fait dans le watcher.

    Mais la solution la plus simple sera donc de "figer" mes résultats avec des setText sur mes TextView directement dans le java, comme pour mes 3 EditText, ce sera plus simple.

    Merci encore

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

Discussions similaires

  1. Fonction vide
    Par vagabon dans le forum Autres éditeurs
    Réponses: 9
    Dernier message: 29/07/2003, 18h23
  2. [CR9] Bug avec les champs à valeur vide ?
    Par Djob dans le forum SAP Crystal Reports
    Réponses: 3
    Dernier message: 15/07/2003, 21h21
  3. [DOM] Balise vide...
    Par carlierd dans le forum Format d'échange (XML, JSON...)
    Réponses: 7
    Dernier message: 02/05/2003, 18h28
  4. [] Datagrid vide après modification des propriétés
    Par SpaceFrog dans le forum VB 6 et antérieur
    Réponses: 9
    Dernier message: 20/09/2002, 16h37
  5. [CR] Avoir seulement une page blanche qd la base est vide???
    Par littleChick dans le forum SAP Crystal Reports
    Réponses: 2
    Dernier message: 13/08/2002, 18h26

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