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 :

Passer une valeur d'une activity a une autre


Sujet :

Android

  1. #21
    Membre confirmé
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Mai 2014
    Messages
    154
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : Industrie

    Informations forums :
    Inscription : Mai 2014
    Messages : 154
    Par défaut
    Voila les modif sont faite mais j'ai toujours le bur au clique pour arriver sur cette activity...

    voici mon code:

    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
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    package ch.srvinfo.interfire.interfire;
     
    import android.app.Activity;
    import android.app.DatePickerDialog;
    import android.app.Dialog;
    import android.app.TimePickerDialog;
    import android.content.Intent;
    import android.content.SharedPreferences;
    import android.os.Bundle;
    import android.os.Environment;
    import android.preference.PreferenceManager;
    import android.support.v7.app.AppCompatActivity;
    import android.view.View;
    import android.widget.AdapterView;
    import android.widget.ArrayAdapter;
    import android.widget.Button;
    import android.widget.DatePicker;
    import android.widget.Spinner;
    import android.widget.TimePicker;
    import android.widget.Toast;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import java.util.Date;
     
     
    public class Inter extends AppCompatActivity {
     
     
     
        //Création button heure date
     
        Date d = new Date();
        SimpleDateFormat f = new SimpleDateFormat("HH:mm");
        String heure = f.format(d);
     
     
        private Bundle NameChef = null;
        private String namefile = ".csv";
        private String userName = "Chef d'inter;";
        private String userName2 = "Nom inter";
        private String orderName = "ordre";
        private File mFile = null;
        private Button mWrite = null;
        private Button mRead = null;
        private String Textv;
     
        Button btnSelectDate, btnSelectTime;
     
        static final int DATE_DIALOG_ID = 0;
        static final int TIME_DIALOG_ID = 1;
     
        // variables to save user selected date and time
        public int year, month, day, hour, minute;
        // declare  the variables to Show/Set the date and time when Time and  Date Picker Dialog first appears
        private int mYear, mMonth, mDay, mHour, mMinute;
     
        // constructor
     
        public Inter() {
            // Assign current Date and Time Values to Variables
            final Calendar c = Calendar.getInstance();
            mYear = c.get(Calendar.YEAR);
            mMonth = c.get(Calendar.MONTH)+1;
            mDay = c.get(Calendar.DAY_OF_MONTH);
            mHour = c.get(Calendar.HOUR_OF_DAY);
            mMinute = c.get(Calendar.MINUTE);
        }
     
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_inter);
    /////////////////////////////Tech preference
        //    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
        //    final String NameCIOK = preferences.getString("VIntent", "NameChef");
    //////////////////////////////// Avec Intent
            //Dans onCreate() par exemple...
       //     Bundle bundle = getIntent().getExtras();
       //     String act2MyValue= bundle.getString(“NameChef“);
     
     
            /////////////////////////////////////////////
            //création des bouton heure et dates
            // get the references of buttons
            btnSelectDate=(Button)findViewById(R.id.buttonSelectDate);
            btnSelectTime=(Button)findViewById(R.id.buttonSelectTime);
     
            // Set ClickListener on btnSelectDate
            btnSelectDate.setOnClickListener(new View.OnClickListener() {
     
                public void onClick(View v) {
                    // Show the DatePickerDialog
                    showDialog(DATE_DIALOG_ID);
                }
            });
     
            // Set ClickListener on btnSelectTime
            btnSelectTime.setOnClickListener(new View.OnClickListener() {
     
                public void onClick(View v) {
                    // Show the TimePickerDialog
                    showDialog(TIME_DIALOG_ID);
                }
            });
    /////////////////////
            Spinner spinner = (Spinner) findViewById(R.id.ordre_spinner);
    // Create an ArrayAdapter using the string array and a default spinner layout
            ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
                    R.array.ordre, android.R.layout.simple_spinner_item);
    // Specify the layout to use when the list of choices appears
            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    // Apply the adapter to the spinner
           spinner.setAdapter(adapter);
     
     
            final int mois = d.getMonth() + 1;
            final int annees = d.getYear() -100;
            final int jours = d.getDay();
            final String datesok = jours + "." + mois + "." + annees;
            mFile = new File(this.getExternalFilesDir(null),"Intervention du_"+d.getDay()+"_"+mois+"_"+annees+"_");
     
     
            mWrite = (Button) findViewById(R.id.Sauvegarde);
            mWrite.setOnClickListener(new View.OnClickListener() {
     
     
                public void onClick(View pView) {
     
     
    //récuperation de l'ordre au clique
                    //Récuperation ordre
                    Spinner spinner = (Spinner) findViewById(R.id.ordre_spinner);
                    String text = spinner.getSelectedItem().toString();
     
                    try {
     
                        // Flux interne
                        FileOutputStream output = openFileOutput(namefile, MODE_PRIVATE);
     
     
                        // Si le fichier est lisible et qu'on peut écrire dedans
                        if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
                                && !Environment.MEDIA_MOUNTED_READ_ONLY.equals(Environment.getExternalStorageState())) {
                            // On crée un nouveau fichier. Si le fichier existe déjà, il ne sera pas créé
    //création de variable pour saut de cellule
                            String Cellule = ";";
                            String Saut = "\n";
                            String NameCI = NameChef + Cellule;
                            String NameInterNew = Cellule;
                            String NameCISpiner =  Cellule;
                            String NameType =  Cellule;
                            String orderName = text + Cellule;
                            String NameDate = datesok + Cellule;
                            String NameHeure = heure + Cellule;
                            String NameDateNew =+day+"-"+month+"-"+year+ Cellule;
                            String NameHeureNew = hour+"-"+minute + Saut;
    // création du fichier
                            mFile.createNewFile();
                            output = new FileOutputStream(mFile+"_"+NameChef+"_"+NameType+".csv", true);
                            // output.write(NameHeure.getBytes());
                            output.flush();
                            output.write(Cellule.getBytes());
                            output.flush();
                            output.write(Cellule.getBytes());
                            output.flush();
                            output.write(Cellule.getBytes());
                            output.write(Cellule.getBytes());
                            output.write(orderName.getBytes());
                            output.write(NameDate.getBytes());
                            output.write(NameHeure.getBytes());
                            output.write(Cellule.getBytes());
                            output.write(Cellule.getBytes());
                            output.write(Cellule.getBytes());
                            output.write(NameDateNew.getBytes());
                            output.write(NameHeureNew.getBytes());
                            output.flush();
                            if (output != null)
                                output.close();
                        }
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
     
     
     
                }
            });
     
     
        }
     
        // Register  DatePickerDialog listener
        private DatePickerDialog.OnDateSetListener mDateSetListener =
                new DatePickerDialog.OnDateSetListener() {
                    // the callback received when the user "sets" the Date in the DatePickerDialog
                    public void onDateSet(DatePicker view, int yearSelected,
                                          int monthOfYear, int dayOfMonth) {
                        year = yearSelected;
                        month = monthOfYear;
                        day = dayOfMonth;
                        // Set the Selected Date in Select date Button
                        btnSelectDate.setText("Date Séléctioner : "+day+"-"+month+"-"+year);
                    }
                };
     
        // Register  TimePickerDialog listener
        private TimePickerDialog.OnTimeSetListener mTimeSetListener =
                new TimePickerDialog.OnTimeSetListener()
                {
                    // the callback received when the user "sets" the TimePickerDialog in the dialog
                    public void onTimeSet(TimePicker view, int hourOfDay, int min) {
                        hour = hourOfDay;
                        minute = min;
     
                        // Set the Selected Date in Select date Button
                        btnSelectTime.setText("Heure Séléctioner :"+hour+"-"+minute);
                    }
                };
     
     
        // Method automatically gets Called when you call showDialog()  method
        @Override
        protected Dialog onCreateDialog(int id) {
            switch (id) {
                case DATE_DIALOG_ID:
                    // create a new DatePickerDialog with values you want to show
                    return new DatePickerDialog(this,
                            mDateSetListener,
                            mYear, mMonth, mDay);
                // create a new TimePickerDialog with values you want to show
                case TIME_DIALOG_ID:
                    return new TimePickerDialog(this,
                            mTimeSetListener, mHour, mMinute, false);
     
     
            }
            return null;
        }
     
        public void Heure_Date(View v) {
            //on creer une nouvelle intent on definit la class de depart ici this et la class d'arrivé ici SecondActivite
            Intent intent=new Intent(this,HeureDate.class);
            //on lance l'intent, cela a pour effet de stoper l'activité courante et lancer une autre activite ici SecondActivite
            startActivity(intent);
     
     
        }
     
     
    }
     
    class SpinnerActivity extends Activity implements AdapterView.OnItemSelectedListener {
     
        public void onItemSelected(AdapterView<?> parent, View view,
                                   int pos, long id) {
            // An item was selected. You can retrieve the selected item using
             parent.getItemAtPosition(pos);
        }
     
        public void onNothingSelected(AdapterView<?> parent) {
            // Another interface callback
        }
    }
    et voici ce que j'ai dans le logcat

    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
    07-21 03:37:03.862 2159-2159/ch.srvinfo.interfire.interfire E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                  Process: ch.srvinfo.interfire.interfire, PID: 2159
                                                                                  java.lang.RuntimeException: Unable to start activity ComponentInfo{ch.srvinfo.interfire.interfire/ch.srvinfo.interfire.interfire.InfoInter}: java.lang.ClassCastException: android.support.v7.widget.AppCompatTextView cannot be cast to android.widget.EditText
                                                                                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2790)
                                                                                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2855)
                                                                                      at android.app.ActivityThread.access$900(ActivityThread.java:181)
                                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1474)
                                                                                      at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                      at android.os.Looper.loop(Looper.java:145)
                                                                                      at android.app.ActivityThread.main(ActivityThread.java:6117)
                                                                                      at java.lang.reflect.Method.invoke(Native Method)
                                                                                      at java.lang.reflect.Method.invoke(Method.java:372)
                                                                                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
                                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
                                                                                   Caused by: java.lang.ClassCastException: android.support.v7.widget.AppCompatTextView cannot be cast to android.widget.EditText
                                                                                      at ch.srvinfo.interfire.interfire.InfoInter.onCreate(InfoInter.java:55)
                                                                                      at android.app.Activity.performCreate(Activity.java:6374)
                                                                                      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
                                                                                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2743)
                                                                                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2855)*
                                                                                      at android.app.ActivityThread.access$900(ActivityThread.java:181)*
                                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1474)*
                                                                                      at android.os.Handler.dispatchMessage(Handler.java:102)*
                                                                                      at android.os.Looper.loop(Looper.java:145)*
                                                                                      at android.app.ActivityThread.main(ActivityThread.java:6117)*
                                                                                      at java.lang.reflect.Method.invoke(Native Method)*
                                                                                      at java.lang.reflect.Method.invoke(Method.java:372)*
                                                                                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)*
                                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)*
    07-21 03:39:50.932 2421-2421/ch.srvinfo.interfire.interfire E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                  Process: ch.srvinfo.interfire.interfire, PID: 2421
                                                                                  java.lang.RuntimeException: Unable to start activity ComponentInfo{ch.srvinfo.interfire.interfire/ch.srvinfo.interfire.interfire.InfoInter}: java.lang.ClassCastException: android.support.v7.widget.AppCompatTextView cannot be cast to android.widget.EditText
                                                                                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2790)
                                                                                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2855)
                                                                                      at android.app.ActivityThread.access$900(ActivityThread.java:181)
                                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1474)
                                                                                      at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                      at android.os.Looper.loop(Looper.java:145)
                                                                                      at android.app.ActivityThread.main(ActivityThread.java:6117)
                                                                                      at java.lang.reflect.Method.invoke(Native Method)
                                                                                      at java.lang.reflect.Method.invoke(Method.java:372)
                                                                                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
                                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
                                                                                   Caused by: java.lang.ClassCastException: android.support.v7.widget.AppCompatTextView cannot be cast to android.widget.EditText
                                                                                      at ch.srvinfo.interfire.interfire.InfoInter.onCreate(InfoInter.java:55)
                                                                                      at android.app.Activity.performCreate(Activity.java:6374)
                                                                                      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
                                                                                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2743)
                                                                                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2855)*
                                                                                      at android.app.ActivityThread.access$900(ActivityThread.java:181)*
                                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1474)*
                                                                                      at android.os.Handler.dispatchMessage(Handler.java:102)*
                                                                                      at android.os.Looper.loop(Looper.java:145)*
                                                                                      at android.app.ActivityThread.main(ActivityThread.java:6117)*
                                                                                      at java.lang.reflect.Method.invoke(Native Method)*
                                                                                      at java.lang.reflect.Method.invoke(Method.java:372)*
                                                                                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)*
                                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)*

  2. #22
    Membre confirmé
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Mai 2014
    Messages
    154
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : Industrie

    Informations forums :
    Inscription : Mai 2014
    Messages : 154
    Par défaut
    J'ai régler mon problème de crash

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
                    NomCITextView = (TextView) findViewById(R.id.NomCITextView);
    était en texte édit!

    merci de toute ces conseil mon fichier est bien plus claire maintenant

    je suis donc tout ouïe pour ce fameux passe entre les deux activity!!

    ou il y avait d'autre chose a faire avant?

  3. #23
    Membre confirmé
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Mai 2014
    Messages
    154
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : Industrie

    Informations forums :
    Inscription : Mai 2014
    Messages : 154
    Par défaut
    Alors je suis a un stade ouje n'ai aucune erreur mais quand je récupéré exrtas dans une variable elle vient ce noter comme ceci
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Bundle[{NAME=mavriable ok}]
    voila mon code sur la premiere

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
                                                    //Création du bundle
                                                    Intent i = new Intent(getApplicationContext(), Inter.class);
     
                                                    i.putExtra("Name",NameCICSV_Write);
                                                    startActivity(i);
    et sur la deuxieme:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
            Bundle extras = getIntent().getExtras();
            if (extras != null) {
                value = extras.getString("name");
                //The key argument here must match that used in the other activity
            }
    Auriez vous une idées de comment récuperer juste ma variable sans tous ce qui est autour?

  4. #24
    Membre confirmé
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Mai 2014
    Messages
    154
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : Industrie

    Informations forums :
    Inscription : Mai 2014
    Messages : 154
    Par défaut
    Voila voila je m'en suis sortie,

    donc pour passer avec mon activity sur mon activity1

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
                                                    //Création du bundle
                                                    Intent i = new Intent(getApplicationContext(), Inter.class);
     
                                                    i.putExtra("Name",NameCICSV_Write);
                                                    i.putExtra("Type",Type_Inter_Write);
                                                    startActivity(i);
    Sur la deux

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
            final Bundle extras = getIntent().getExtras();
            final String tmp = extras.getString("Name");
            final String TypeINtent = extras.getString("Type");
            if (extras != null) {
                value = extras.getString("");
                //The key argument here must match that used in the other activity
            }
    dans tous les cas merci infiniment pour ton aide, tes explications claire et ta patience qui ont été très précieuses!!

    je met le sujet comme résolut!!

+ Répondre à la discussion
Cette discussion est résolue.
Page 2 sur 2 PremièrePremière 12

Discussions similaires

  1. Réponses: 21
    Dernier message: 05/02/2015, 11h26
  2. [XL-2000] Remplir une valeur dans cellule à partir d'une valeur precise d'un fichier texte
    Par cactus666 dans le forum Macros et VBA Excel
    Réponses: 0
    Dernier message: 26/01/2010, 10h31
  3. Réponses: 7
    Dernier message: 16/03/2007, 19h28
  4. passer la valeur d'un return dans une méthode
    Par belukrin dans le forum Langage
    Réponses: 1
    Dernier message: 25/03/2006, 06h58
  5. Réponses: 2
    Dernier message: 12/12/2004, 14h19

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