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 :

Force close lors du double clic sur un edittext insérant un datepicker


Sujet :

Android

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Femme Profil pro
    Étudiant
    Inscrit en
    Avril 2015
    Messages
    33
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 34
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2015
    Messages : 33
    Par défaut Force close lors du double clic sur un edittext insérant un datepicker
    Bonjour

    Le code 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
    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
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
     
     
     
    <?xml version="1.0" encoding="utf-8"?>
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ScrollView01"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/medt2mud"
     
    >
     
    <LinearLayout android:layout_width="match_parent"
    android:layout_height="match_parent">
     
     
    <RelativeLayout
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:paddingBottom="@dimen/activity_vertical_margin"
       android:paddingLeft="@dimen/activity_horizontal_margin"
       android:paddingRight="@dimen/activity_horizontal_margin"
       android:paddingTop="@dimen/activity_vertical_margin"
       >
     
        <LinearLayout  
         android:id="@+id/linearLayout12"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:orientation="vertical"
         android:gravity="center" >
     
            	<LinearLayout
                android:id="@+id/linearLayout1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                 android:gravity="center" >
                   <TextView
     
            android:layout_width="300dp"
            android:layout_height="50dp"
            android:text="Formulaire de Recherche"
            android:textSize="20sp"
            android:textStyle="bold" 
             android:padding="12dp"
             android:gravity="center"
             android:textColor="#003366"
     
             android:layout_marginTop="10dp"
     
             />
     
            	    	<LinearLayout
    	                android:layout_width="fill_parent"
    	                android:layout_height="wrap_content"
    	                android:orientation="vertical" >
     
    		                     <TextView
                    android:id="@+id/textView11"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/COUNTRY_LABEL"/>
     
                <AutoCompleteTextView
                    android:id="@+id/autocompleteCountry"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:hint="AU DEPART DE "
                    android:background="@drawable/list_selector2"
                    android:padding="7dp"
                    android:textStyle="bold"
                    android:layout_marginTop="4dp" 
                    android:layout_marginLeft="4dp"	
                    android:inputType="textCapSentences" >
     
                    <requestFocus />
                </AutoCompleteTextView>
     
     
    		                    <LinearLayout
    	                android:layout_width="fill_parent"
    	                android:layout_height="wrap_content"
    	                android:orientation="horizontal" >
     
     
     
                         <EditText
    	                    android:id="@+id/start_date"
    	                    android:layout_width="250dp"
    	                    android:layout_height="wrap_content"
    	                    android:layout_marginTop="20dp"
    	                    android:layout_alignParentTop="true"
    	                    android:layout_centerHorizontal="true"
    	                    android:layout_marginLeft="4dp"	                    
    	                    android:editable="false"	                   
    	                    android:inputType="date"	                    
    	                    android:focusableInTouchMode="false"	                     
    	                    android:hint="DATE DE DEPART "
    	                    android:textStyle="bold"
    	                    android:textColor="#000"
    	                    android:background="@drawable/list_selector2"
    	                    android:padding="7dp"
    	                    android:drawableRight="@drawable/ical_488">
     
                          </EditText>
     
     
            </LinearLayout>             
     
     
     
     
     
     
      			       </LinearLayout>
     
     
            	    	<LinearLayout
    	                android:layout_width="fill_parent"
    	                android:layout_height="wrap_content"
    	                android:orientation="horizontal" >
     
    	                    <TextView
                    android:id="@+id/textView22"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/COUNTRY_LABEL"/>
     
                <AutoCompleteTextView
                    android:id="@+id/autocompleteCountry2"
                   android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="25dp"
                    android:layout_marginLeft="4dp"	
                    android:hint="A DESTINATION DE"
                    android:textStyle="bold" 
                    android:background="@drawable/list_selector2" 
                    android:padding="7dp"
                    android:inputType="textCapSentences">
     
     
                </AutoCompleteTextView>
     
     
     
            	  </LinearLayout>
     
     
            </LinearLayout>   	
     
     
     
     
     
     
     
     
     
     
     
     
       <LinearLayout
    	                android:layout_width="fill_parent"
    	                android:layout_height="wrap_content"
    	                android:orientation="horizontal" >
     
                          <EditText
    	                    android:id="@+id/end_date"
    	                    android:layout_width="250dp"
    	                    android:layout_height="wrap_content"
    	                    android:layout_alignParentTop="true"
    	                    android:layout_centerHorizontal="true"
    	                    android:layout_marginLeft="4dp"
    		                android:layout_marginTop="20dp"
    		                android:focusableInTouchMode="false"
    		                android:editable="false"	                   
    	                    android:inputType="date"
    	                    android:hint="DATE DE RETOUR"
    	                    android:textStyle="bold"  
    	                    android:textColor="#000"
    	                    android:drawableRight="@drawable/ical_488" 
    	                    android:background="@drawable/list_selector2"
    	                    android:padding="7dp" >
     
                         </EditText>
     
            	  </LinearLayout>
     
     
     
     
     
     
     
       <RelativeLayout
           android:layout_width="fill_parent"
           android:layout_height="fill_parent"
           android:orientation="horizontal" >    	
     
     
     
     
            	<Spinner
                android:id="@+id/classe"
                android:layout_width="wrap_content"
                android:layout_height="35dp"
                 android:layout_alignParentRight="true"
                android:layout_marginTop="32dp"
     
     
                />
     
     
    			<RadioGroup
    			android:id="@+id/group"
    			android:layout_width="fill_parent"
    			android:layout_height="wrap_content"
    			android:orientation="vertical"
    			android:layout_marginLeft="16dp"
    			android:checkedButton="@+id/radioButton1"
     
    			>
    					        <RadioButton
    					        android:id="@+id/radioButton1"
    					        android:layout_width="wrap_content"
    					        android:layout_height="wrap_content"
    					        android:layout_above="@+id/rechercher"
    					        android:text="  Aller - retour"
    					        android:layout_marginTop="10dp"
    					        android:textColor="#000"
    					        android:textStyle="bold"
    					        android:button="@drawable/custom_radio_button_selector"
    					         />
     
     
    							<RadioButton
    							android:id="@+id/radioButton2"
    					        android:layout_width="wrap_content"
    					        android:layout_height="wrap_content"
    					        android:text="  Aller-simple"
    					        android:textColor="#000"
    					        android:textStyle="bold" 
    					        android:button="@drawable/custom_radio_button_selector"
    							/>
    			</RadioGroup>
    </RelativeLayout>    	
     
     
     
     
            	<LinearLayout
           android:layout_width="fill_parent"
           android:layout_height="fill_parent"
           android:orientation="vertical" >
     
     
     
    <LinearLayout
    	  android:layout_width="fill_parent"
    	  android:layout_height="wrap_content"
    	  android:orientation="horizontal" >
     
                    <TextView
                    android:id="@+id/textView1"
                    android:layout_width="60dp"
                    android:layout_height="30dp"
                    android:layout_alignParentLeft="true"
                    android:layout_below="@+id/Enfants"
                     android:layout_marginLeft="60dp"
                     android:layout_marginTop="9dp"
                    android:text="Adultes" 
                    android:textColor="#000"
                    android:textStyle="bold"/>
     
                   <Spinner
                    android:id="@+id/Adultes"
                    android:layout_width="wrap_content"
                    android:layout_height="35dp"
                    android:layout_alignParentTop="true"
     
                    android:layout_marginTop="10dp" 
                    />
     
                   <TextView
                       android:id="@+id/textView4"
                       android:layout_width="120dp"
                       android:layout_height="30dp"
                       android:layout_marginRight="70dp"
                       android:layout_marginTop="9dp"
                       android:text="  ( 12 + ans )" 
                       android:textColor="#000"
                       android:textStyle="bold"/>
     
    </LinearLayout>
     
     
     
     
    <LinearLayout
    	  android:layout_width="fill_parent"
    	  android:layout_height="wrap_content"
    	  android:orientation="horizontal" >
     
     
                    <TextView
                    android:id="@+id/textView2"
                    android:layout_width="60dp"
                    android:layout_height="30dp"
                    android:layout_above="@+id/Enfants"
                    android:layout_alignRight="@+id/textView1"
                     android:layout_marginLeft="60dp"
                    android:text="Enfants"                
                    android:textColor="#000"
                     android:textStyle="bold"/>
     
                    <Spinner
                    android:id="@+id/Enfants"
                    android:layout_width="wrap_content"
                    android:layout_height="35dp"
     
                    android:layout_marginTop="3dp" />
     
                    <TextView
                    android:id="@+id/textView5"
                    android:layout_width="120dp"
                    android:layout_height="30dp"
                    android:layout_above="@+id/Enfants"
                    android:layout_alignParentRight="true"
                    android:layout_marginRight="70dp"
                    android:text="  ( 2 - 11 ans )"
                    android:textColor="#000"
     
                android:textStyle="bold" />
     
    </LinearLayout>
     
     
     
     
     
    <LinearLayout
    	  android:layout_width="fill_parent"
    	  android:layout_height="wrap_content"
    	  android:orientation="horizontal" >
     
     
                <TextView
                android:id="@+id/textView33"
                android:layout_width="60dp"
                android:layout_height="30dp"
                android:text="Bébés" 
     
                android:layout_marginLeft="60dp"
                android:textColor="#000"
                android:textStyle="bold"/>
     
     
                    <Spinner
                    android:id="@+id/bebes"
                    android:layout_width="wrap_content"
                    android:layout_height="35dp"
                    android:layout_below="@id/Adultes"
     
                    android:layout_marginTop="3dp" />
     
     
     
                   <TextView
                    android:id="@+id/textView6"
                    android:layout_width="140dp"
                    android:layout_height="30dp"
                    android:layout_below="@+id/Adultes"
                    android:layout_toRightOf="@+id/bebes"
                    android:text="  ( Moins de 2 ans )" 
                    android:textColor="#000"
                android:textStyle="bold"/>
     
     
    </LinearLayout>
    </LinearLayout>
     
     
     
      <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
     
    android:orientation="vertical"
     android:gravity="center"
    >
     
     
            <Button
                android:id="@+id/rechercher"
                android:layout_width="120dp"
                android:layout_height="50dp"  
     
    	        android:layout_marginTop="15dp"
    	        android:layout_marginBottom="15dp"
    	       android:gravity="center"
     
     
     
     
    	        android:text=" Rechercher "
    	        android:textColor="#000"
                android:textStyle="bold"
                android:background="@drawable/a9p_09_11_00072"
     
     
     
                />
             </LinearLayout>
     
    </LinearLayout>
     
    </RelativeLayout>
    </LinearLayout>
     
    </ScrollView>
    Le code 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
    package com.example.agence;
     
    import android.support.v7.app.ActionBarActivity;
    import android.os.Bundle;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.os.Bundle;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.KeyEvent;
    import android.view.MotionEvent;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.view.View.OnKeyListener;
    import android.widget.Button;
    import android.widget.CheckBox;
    import android.widget.EditText;
    import android.widget.RadioGroup;
    import android.widget.TextView;
    import android.widget.Toast;
    public class RechercherActivity extends ActionBarActivity {
    	//Button retour = null;
    	Button recherche_rapide = null;
    	Button offre = null;
    	Button vols_disponibles = null;
    	//
    	TextView text = null;
    	@Override
    	protected void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.rechercher);
    		getSupportActionBar().hide();
     
     
     
    		// retour = (Button)findViewById(R.id.retour);
    	        recherche_rapide = (Button)findViewById(R.id.recherche_rapide);
    	        offre = (Button)findViewById(R.id.offre);
    	        vols_disponibles = (Button)findViewById(R.id.vols_disponibles);
    	        //
    	        text = (TextView)findViewById(R.id.text);
     
    	    //	retour.setOnClickListener(retourListener);
    			recherche_rapide.setOnClickListener(recherche_rapideListener);
    			offre.setOnClickListener(offreListener);
    			//vols_disponibles.setOnClickListener(vols_disponiblesListener);
     
    	}
     
    	@Override
    	public boolean onCreateOptionsMenu(Menu menu) {
    		// Inflate the menu; this adds items to the action bar if it is present.
    		getMenuInflater().inflate(R.menu.rechercher, menu);
    		return true;
    	}
     
    	@Override
    	public boolean onOptionsItemSelected(MenuItem item) {
    		// Handle action bar item clicks here. The action bar will
    		// automatically handle clicks on the Home/Up button, so long
    		// as you specify a parent activity in AndroidManifest.xml.
    		int id = item.getItemId();
    		if (id == R.id.action_settings) {
    			return true;
    		}
    		return super.onOptionsItemSelected(item);
    	}
     
    /*	private OnClickListener retourListener = new OnClickListener() {
    	    @Override
    	    public void onClick(View v) {
     
    	      Intent secondeActivite=new Intent(RechercherActivity.this, AcceuilActivity.class);
    	      startActivity(secondeActivite);
    	    }
    	  };*/
     
     
    	  private OnClickListener recherche_rapideListener = new OnClickListener() {  
    		    @Override
    		    public void onClick(View v) {
     
    		      Intent secondeActivite=new Intent(RechercherActivity.this, RechercheRapideActivity.class);
    		      startActivity(secondeActivite);
    		    }
    		  };
     
    		  private OnClickListener offreListener = new OnClickListener() {
    			    @Override
    			    public void onClick(View v) {
     
    			      Intent secondeActivite=new Intent(RechercherActivity.this, List_offre_non_clientActivity.class);
    			      startActivity(secondeActivite);
    			    }
    			  };
     
     
    }



    quand je double clic sur l'editext une erreur se produit (force close). Voici le résultat du logcat
    Nom : Capture.PNG
Affichages : 128
Taille : 47,7 Ko

    Merci.

  2. #2
    Expert confirmé

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

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

    Informations forums :
    Inscription : Février 2007
    Messages : 4 253
    Billets dans le blog
    3
    Par défaut
    Dommage il manque le code ou tu fais appel à ton fragment DatePicker....

    Mais sinon l'idée c'est que:

    Tu n'affiche le DatePicker *que* si il n'est pas déjà affiché.

    La raison est probablement que:
    * Le premier click est géré => demande d'affichage du DatePicker....
    * Le second click est géré (avant que le DatePicker n'ait eu le temps de vraiment s'afficher) => demande d'affichage du DatePicker *à nouveau*
    * Le main-looper, va commencer à afficher les DatePicker.... pour le premier c'est bon... pour le second => IllegalStateException

  3. #3
    Membre averti
    Femme Profil pro
    Étudiant
    Inscrit en
    Avril 2015
    Messages
    33
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 34
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2015
    Messages : 33
    Par défaut
    Voici le code java :fragment DatePicker
    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
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    package com.example.agence;
     
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import java.util.Date;
     
    import android.app.DatePickerDialog;
    import android.app.Dialog;
    //import android.app.DialogFragment;
    import android.content.Intent;
    import android.os.Bundle;
    import android.support.v4.app.DialogFragment;
    import android.support.v7.app.ActionBarActivity;
    import android.text.Editable;
    import android.text.TextWatcher;
    import android.util.Log;
    import android.view.Gravity;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.ArrayAdapter;
    import android.widget.AutoCompleteTextView;
    import android.widget.Button;
    import android.widget.DatePicker;
    import android.widget.EditText;
    import android.widget.LinearLayout;
    import android.widget.RadioButton;
    import android.widget.RadioGroup;
    import android.widget.Spinner;
    import android.widget.TextView;
    import android.widget.Toast;
     
    public class RechercheRapideActivity extends ActionBarActivity implements View.OnClickListener {
    	private Fonction_BDD datasource;
     
    	 Button rechercher = null;//déclaration du bouton retour 
    	   //
    	    Date d;
    	    Date f;
     
    	    long ff=9223372036854775807L;
     
    	    Date d1;
    	    Date f1;
     
     
    	  static String Age="cc";
    	   String value;
    	   static String Age1="ccd";
    	   String value1;
    	   static String Age2="cca";
    	   String value2;
    	   static String Age3="ccv";
    	   String value3;
    	   static String Age4="ccqs";
    	   String value4;
    	   static String Age5="cch";
    	   String value5;   
    	   static String Age6="cckiu";
    	   String value6;
    	   static String Age7="ccmpol";
    	   String value7;
    	   static String Age8="ccbv";
    	   String value8="ll";
     
     
    	   RadioGroup group = null;
     
    	   private AutoCompleteTextView autocompleteCountry= null;
    	   private AutoCompleteTextView autocompleteCountry2= null;
     
    	//  private AutoCompleteTextView DateDeDepart= null; // date de départ
    	  // private AutoCompleteTextView DateDeRetour= null; // date de retour
     
     
     
    	    //private Button startPickDate; // déclaration du bouton calendrier aller
    	    //private Button endPickDate; //déclaration du bouton calendrier retour
     
    	    //private Calendar startDate;
    	    //private Calendar endDate;
     
    	    //static final int DATE_DIALOG_ID = 0;
     
    	    //private TextView activeDateDisplay;
    	    //private Calendar activeDate;
     
    	   private EditText mStartTime;
    	    private EditText mEndTime;
     
     
     
    	    private DatePickerDialogFragment mDatePickerDialogFragment; 
     
     
     
     
    	   String[] cl = { "Economique", "Affaires", "Première" }; //valeurs possibles pr le spinner classe
     
    	   String[] premierDigit = { "1","2","3","4","5","6","7","8","9"}; //valeurs possibles pr le spinner adultes
     
    	   String[] deuxiemeDigit = {"0", "1","2","3"};  //valeurs possibles pr le spinner enfants
     
    	   String[] troisiemeDigit = {"0","1", "2","3", "4","5","6"};  //valeurs possibles pr le spinner bébés
     
    	   Spinner s;  // spinner classe
    	   Spinner s1; //spinner adultes
    	   Spinner s2; //spinner enfants
    	   Spinner s3; //spinner bébés
     
     
     
     
    	@Override
     
     
    	protected void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.recherche_rapide);
    		getSupportActionBar().hide();
     
     
    		mStartTime = (EditText) findViewById(R.id.start_date);
            mEndTime = (EditText) findViewById(R.id.end_date);
            mDatePickerDialogFragment = new DatePickerDialogFragment();
     
            mStartTime.setOnClickListener(this);
            mEndTime.setOnClickListener(this);
     
     
     
    		/*  capture our View elements for the start date function   */
    	      //  startDateDisplay = (TextView) findViewById(R.id.startDateDisplay);
    //	        DateDeDepart = (AutoCompleteTextView) findViewById(R.id.DateDeDepart);
    	//        startPickDate = (Button) findViewById(R.id.startPickDate);
     
    	        /* get the current date */
    	  //      startDate = Calendar.getInstance();
     
    	        /* add a click listener to the button   
    	        startPickDate.setOnClickListener(new View.OnClickListener() {
    	            public void onClick(View v) {
    	                showDateDialog(DateDeDepart, startDate);
    	            }
    	        });
     
    	         capture our View elements for the end date function 
    	       // DateDeRetour = (TextView) findViewById(R.id.DateDeRetour);
    	        DateDeRetour = (AutoCompleteTextView) findViewById(R.id.DateDeRetour);
    	        endPickDate = (Button) findViewById(R.id.endPickDate);
     
    	         get the current date 
    	        endDate = Calendar.getInstance();
     
    	         add a click listener to the button   
    	        endPickDate.setOnClickListener(new View.OnClickListener() {
    	            public void onClick(View v) {
    	                showDateDialog(DateDeRetour, endDate);
    	            }
    	        });
     
    	         display the current date (this method is below)  
    	        updateDisplay(DateDeDepart, startDate);
    	        updateDisplay(DateDeRetour, endDate);
    	        */
     
     
     
     
     
    		 rechercher = (Button)findViewById(R.id.rechercher);
     
    		 rechercher.setOnClickListener(rechercherListener);
     
     
    		s = (Spinner) findViewById(R.id.classe);
     
         ArrayAdapter<String> adapter0 = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, cl);
     
         s.setAdapter(adapter0);
     
    		s1 = (Spinner) findViewById(R.id.Adultes);
     
         ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, premierDigit);
     
         s1.setAdapter(adapter1);
     
         s2 = (Spinner) findViewById(R.id.Enfants);
     
         ArrayAdapter<String> adapter2 = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, deuxiemeDigit);
     
         s2.setAdapter(adapter2);
     
         s3 = (Spinner) findViewById(R.id.bebes);
     
         ArrayAdapter<String> adapter3 = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, troisiemeDigit);
     
         s3.setAdapter(adapter3);
     
     
     
         autocompleteCountry = (AutoCompleteTextView) findViewById(R.id.autocompleteCountry);
         autocompleteCountry2 = (AutoCompleteTextView) findViewById(R.id.autocompleteCountry2);
     
    		datasource = new Fonction_BDD(RechercheRapideActivity.this);
    		datasource.open();
     
    		String[] countries = datasource.getAllCountriesss();
    		String[] countries_Arr = datasource.getAllCountriesss_Arr();
     
         // Print out the values to the log
         for(int i = 0; i < countries.length; i++)
         {
             Log.i(this.toString(), countries[i]);
         }
     
         for(int i = 0; i < countries_Arr.length; i++)
         {
             Log.i(this.toString(), countries_Arr[i]);
         }
     
         ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_item_1, countries);
         autocompleteCountry.setAdapter(adapter);
     
         ArrayAdapter<String> adapter11 = new ArrayAdapter<String>(this, R.layout.list_item_2, countries_Arr);
         autocompleteCountry2.setAdapter(adapter11);
     
     
     
     
     
     
     
         group = (RadioGroup)findViewById(R.id.group);
     
     
     
    	}
     
     
    	@Override
        public void onClick(View v) {
            int id = v.getId();
            if (id == R.id.start_date) {
     
                mDatePickerDialogFragment.setFlag(DatePickerDialogFragment.FLAG_START_DATE);
                mDatePickerDialogFragment.show(getSupportFragmentManager(), "datePicker");
     
     
     
            } else if (id == R.id.end_date) {
                mDatePickerDialogFragment.setFlag(DatePickerDialogFragment.FLAG_END_DATE);
                mDatePickerDialogFragment.show(getSupportFragmentManager(), "datePicker");
            }
     
     
     
        }
     
    	public class DatePickerDialogFragment extends DialogFragment implements
        DatePickerDialog.OnDateSetListener {
    public static final int FLAG_START_DATE = 0;
    public static final int FLAG_END_DATE = 1;
     
    private int flag = 0;
     
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        Calendar calendar = Calendar.getInstance();
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH);
        int day = calendar.get(Calendar.DAY_OF_MONTH);
     
        return new DatePickerDialog(getActivity(), this, year, month, day);
     
    }
     
    public void setFlag(int i) {
        flag = i;
     
    }
     
    @Override
    public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(year, monthOfYear, dayOfMonth);        
     
     
        SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy");
     
        if (flag == FLAG_START_DATE) {
     
            mStartTime.setText(format.format(calendar.getTime()));
        } else if (flag == FLAG_END_DATE) {
            mEndTime.setText(format.format(calendar.getTime()));    
        }
     
    } 
     
     
    }
     
     
     
     
     
     
     
     
     
    	@Override
    	public boolean onCreateOptionsMenu(Menu menu) {
    		// Inflate the menu; this adds items to the action bar if it is present.
    		getMenuInflater().inflate(R.menu.main, menu);
    		return true;
    	}
     
    	@Override
    	public boolean onOptionsItemSelected(MenuItem item) {
    		// Handle action bar item clicks here. The action bar will
    		// automatically handle clicks on the Home/Up button, so long
    		// as you specify a parent activity in AndroidManifest.xml.
    		int id = item.getItemId();
    		if (id == R.id.action_settings) {
    			return true;
    		}
    		return super.onOptionsItemSelected(item);
    	}
     
     
     
     
     
     
     
     
     
     
    	  private OnClickListener rechercherListener = new OnClickListener() {
    		    @Override
    		    public void onClick(View v) {
     
     
    		    	value= s.getSelectedItem().toString();
    		    	value1=  s1.getSelectedItem().toString();
    		     	value2=s2.getSelectedItem().toString();
    		    	value3=s3.getSelectedItem().toString();
     
    		    	value4=autocompleteCountry.getText().toString();
    		     	value5=autocompleteCountry2.getText().toString();
    		    	value6=mStartTime.getText().toString();
    		    	value7=mEndTime.getText().toString();
    		    	final RadioButton group1_c =(RadioButton)findViewById(group.getCheckedRadioButtonId());
    		    	 String r1=(String)group1_c.getText();
     
     
    		    	  datasource.open();            
     
     
     
    		    	   // Client tabb=null;
    		    	  // tabb=values.toArray(tabb);
    		    	    int rep=0;
     
     
    		    	    boolean livreFromBdd = datasource.checkNom_aero(value4);
     
    		            //Si un livre est retourné (donc si le livre à bien été ajouté à la BDD)
    		          if(livreFromBdd != true){ 
    		            	rep=rep+1;
    		            } 
     
     
     
    		          int rep1=0;
     
     
    		    	    boolean livreFromBdd1 = datasource.checkNom_aero_arr(value5);
     
    		            //Si un livre est retourné (donc si le livre à bien été ajouté à la BDD)
    		          if(livreFromBdd1 != true){ 
    		            	rep1=rep1+1;
    		            } 
     
    		          datasource.close();
     
     
    		    	if(((value4.equals(""))|| (value5.equals(""))|| (value6.equals("")))&&(r1.equals("  Aller-simple"))){
    		    		message();
    		    	}
    		    	else if(((value4.equals(""))|| (value5.equals(""))|| (value6.equals(""))|| (value7.equals("")))&&(r1.equals("  Aller - retour"))){
    		    		message();
    		    	}
    		    	else if((rep>0) &(rep1>0)){
    		    		rep=0;
    		    		rep1=0;
    		    		message_dep_arr();
    		    	}
    		    	else if(rep>0){
    		    		rep=0;
    		    		message_dep();
    		    	}
                    else if(rep1>0){
    		    	rep1=0;	
    		    	message_arr();
    		    	}
     
    		    	else{
     
     
     
    		    		Calendar cal = Calendar.getInstance();
    			    	 SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
    			    	 try {
    						 d = sdf.parse(value6);
    						 if(!value7.equals(""))
    						 f = sdf.parse(value7);
    					} catch (ParseException e) {
    						// TODO Auto-generated catch block
    						e.printStackTrace();
    					}
     
     
     
     
    			    	long dd= d.getTime();
    			    	 if(!value7.equals(""))
    				    	{ ff=f.getTime();
    				    	}
     
     
     
     
     
     
     
     
    			    	 if(dd>ff){
    			    		boite();
    			    		//la date debu est sup a date fin
    			    	}   
     
    			    	else{
     
     
     
     
    		    	//if(group.getCheckedRadioButtonId() == R.id.group)
    		        	 //     value8="2";
     
     
    		    Intent secondeActivite=new Intent(RechercheRapideActivity.this, ResultatRechercheRapideActivity.class);
     
     
    		   // Bundle bundleExtras =new Bundle(); 
    		   // bundleExtras.putString(Age,value);
    		    //secondeActivite.putExtras(bundleExtras) ;
    		      secondeActivite.putExtra(Age,value);    
    		      secondeActivite.putExtra(Age1,value1);  
    		      secondeActivite.putExtra(Age2,value2);
    		      secondeActivite.putExtra(Age3,value3);
    		      secondeActivite.putExtra(Age4,value4);
    		      secondeActivite.putExtra(Age5,value5);
    		      secondeActivite.putExtra(Age6,value6);
    		      secondeActivite.putExtra(Age7,value7);
    		      secondeActivite.putExtra(Age8,r1);
     
    		     startActivity(secondeActivite);}}
    		    }
    		  };
     
     
     
     
     
     
     
    			  /*
    			  private void updateDisplay(TextView dateDisplay, Calendar date) {
    			        dateDisplay.setText(
    			                new StringBuilder()
    			                    // Month is 0 based so add 1 
    			                    .append(date.get(Calendar.DAY_OF_MONTH)).append(" ")
    			                    .append(date.get(Calendar.MONTH)+ 1).append(" ")
    			                    .append(date.get(Calendar.YEAR)).append(""));
     
    			    }
     
    			    public void showDateDialog(TextView dateDisplay, Calendar date) {
    			        activeDateDisplay = dateDisplay;
    			        activeDate = date;
    			        showDialog(DATE_DIALOG_ID);
    			    }
     
    			    private OnDateSetListener dateSetListener = new OnDateSetListener() {
    			        @Override
    			        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
    			            activeDate.set(Calendar.YEAR, year);
    			            activeDate.set(Calendar.MONTH, monthOfYear);
    			            activeDate.set(Calendar.DAY_OF_MONTH, dayOfMonth);
    			            updateDisplay(activeDateDisplay, activeDate);
    			            unregisterDateDisplay();
    			        }
    			    };
     
    			    private void unregisterDateDisplay() {
    			        activeDateDisplay = null;
    			        activeDate = null;
    			    }
     
    			    @Override
    			    protected Dialog onCreateDialog(int id) {
    			        switch (id) {
    			            case DATE_DIALOG_ID:
    			                return new DatePickerDialog(this, dateSetListener, activeDate.get(Calendar.YEAR), activeDate.get(Calendar.MONTH), activeDate.get(Calendar.DAY_OF_MONTH));
    			        }
    			        return null;
    			    }
     
    			    @Override
    			    protected void onPrepareDialog(int id, Dialog dialog) {
    			        super.onPrepareDialog(id, dialog);
    			        switch (id) {
    			            case DATE_DIALOG_ID:
    			                ((DatePickerDialog) dialog).updateDate(activeDate.get(Calendar.YEAR), activeDate.get(Calendar.MONTH), activeDate.get(Calendar.DAY_OF_MONTH));
    			                break;
    			        }
    			    }*/	
     
    			    private TextWatcher textWatcher = new TextWatcher() {
     
    				    @Override
    				    public void onTextChanged(CharSequence s, int start, int before, int count) {
     
    				    }
     
    				    @Override
    				    public void beforeTextChanged(CharSequence s, int start, int count,
    				      int after) {
     
    				    }
     
     
    					@Override
    					public void afterTextChanged(Editable s) {
    						// TODO Auto-generated method stub
     
    					}
    				  };
     
    				  public void message(){
    					  Toast v=Toast.makeText(this, " Veuillez remplir tous les champs ", Toast.LENGTH_LONG);
    					  LinearLayout layout = (LinearLayout) v.getView();
    		    			if (layout.getChildCount() > 0) {
    		    			  TextView tv = (TextView) layout.getChildAt(0);
    		    			  tv.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
    		    			}
    					  v.setGravity(Gravity.CENTER, 0, 0);
    					  v.show();
    			   }
     
     
    				  public void message_dep(){
    					  Toast v=Toast.makeText(this, " L'aéroport "+value4+" n'existe pas ", Toast.LENGTH_LONG);
    					  LinearLayout layout = (LinearLayout) v.getView();
    		    			if (layout.getChildCount() > 0) {
    		    			  TextView tv = (TextView) layout.getChildAt(0);
    		    			  tv.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
    		    			}
    					  v.setGravity(Gravity.CENTER, 0, 0);
    					  v.show();
    			   }
     
    				  public void message_dep_arr(){
    					  Toast v=Toast.makeText(this, " L'aéroport "+value4+" et "+value5+" n'existent pas ", Toast.LENGTH_LONG);
    					  LinearLayout layout = (LinearLayout) v.getView();
    		    			if (layout.getChildCount() > 0) {
    		    			  TextView tv = (TextView) layout.getChildAt(0);
    		    			  tv.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
    		    			}
    					  v.setGravity(Gravity.CENTER, 0, 0);
    					  v.show();
    			   }
     
    				  public void message_arr(){
    					  Toast v=Toast.makeText(this, " L'aéroport "+value5+" n'existe pas ", Toast.LENGTH_LONG);
    					  LinearLayout layout = (LinearLayout) v.getView();
    		    			if (layout.getChildCount() > 0) {
    		    			  TextView tv = (TextView) layout.getChildAt(0);
    		    			  tv.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
    		    			}
    					  v.setGravity(Gravity.CENTER, 0, 0);
    					  v.show();
    			   }
     
    				  public void boite(){
    					 Toast v= Toast.makeText(this, " La date de départ est supérieure à la date de retour ", Toast.LENGTH_LONG);
    					  LinearLayout layout = (LinearLayout) v.getView();
    		    			if (layout.getChildCount() > 0) {
    		    			  TextView tv = (TextView) layout.getChildAt(0);
    		    			  tv.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
    		    			}
    					  v.setGravity(Gravity.CENTER, 0, 0);
    					  v.show();
    				  }
     
    }

Discussions similaires

  1. [AC-2003] Message d'erreur lors du double clic sur un graphique
    Par ostrich95 dans le forum IHM
    Réponses: 3
    Dernier message: 26/05/2014, 15h49
  2. double postback lors d'un clic sur le bouton
    Par Wnejla dans le forum ASP.NET
    Réponses: 6
    Dernier message: 29/03/2013, 02h32
  3. Réponses: 5
    Dernier message: 07/07/2011, 09h39
  4. ouverture d'un programme par double clic sur un fichier
    Par zieg18 dans le forum Visual C++
    Réponses: 6
    Dernier message: 12/07/2006, 10h02
  5. comment autoriser le double clic sur un champ desactivé ?
    Par linou dans le forum Général JavaScript
    Réponses: 6
    Dernier message: 28/04/2005, 17h23

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