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

Composants graphiques Android Discussion :

Problème clique bouton


Sujet :

Composants graphiques Android

  1. #1
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Septembre 2012
    Messages
    79
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Niger

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Transports

    Informations forums :
    Inscription : Septembre 2012
    Messages : 79
    Points : 64
    Points
    64
    Par défaut Problème clique bouton
    Bonsoir à tous!

    Dans mon App lorsque je clique sur le bouton Login,il ne se passe rien,voici mes codes :
    Class Login
    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
    public class login extends AppCompatActivity {
        DatabaseHelper myDb;
        EditText TextPseudo,Textphone;
        Button b_Login;
     
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_login);
     
            TextPseudo=(EditText)findViewById(R.id.editTextPseudo) ;
            Textphone=(EditText)findViewById(R.id.input_phone);
     
     
            b_Login=(Button)findViewById(R.id.buttonLogin);
        }
     
        public void viewAll()
        {
            b_Login.setOnClickListener(
                    new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
     
                            myDb.getData();
                       startActivity(new Intent(getApplicationContext(),Menu.class));
     
     
     
                        }
                    }
            );
        }
    et le log Cat:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    09-25 15:51:13.551 10156-10156/com.example.sofari.tiffanezni E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                   Process: com.example.sofari.tiffanezni, PID: 10156
                                                                                   java.lang.IllegalStateException: Could not find method onClick(View) in a parent or ancestor Context for android:onClick attribute defined on view class android.support.v7.widget.AppCompatButton with id 'buttonLogin'
                                                                                       at android.view.View$DeclaredOnClickListener.resolveMethod(View.java:4757)
                                                                                       at android.view.View$DeclaredOnClickListener.onClick(View.java:4716)
                                                                                       at android.view.View.performClick(View.java:5637)
                                                                                       at android.view.View$PerformClick.run(View.java:22429)
                                                                                       at android.os.Handler.handleCallback(Handler.java:751)
                                                                                       at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                       at android.os.Looper.loop(Looper.java:154)
                                                                                       at android.app.ActivityThread.main(ActivityThread.java:6119)
                                                                                       at java.lang.reflect.Method.invoke(Native Method)
                                                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
                                                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

    quelqu'un peut il m'aider,merci!

  2. #2
    Membre confirmé
    Avatar de BeeApps
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juillet 2017
    Messages
    86
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 30
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Juillet 2017
    Messages : 86
    Points : 615
    Points
    615
    Par défaut
    Salut,

    Peux-tu donner ton activity_login.xml

  3. #3
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Septembre 2012
    Messages
    79
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Niger

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Transports

    Informations forums :
    Inscription : Septembre 2012
    Messages : 79
    Points : 64
    Points
    64
    Par défaut
    bonjour!
    voici l'activity_login;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
     <ScrollView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="@color/colorAccent"
            android:fitsSystemWindows="true"
            tools:layout_editor_absoluteX="0dp"
            tools:layout_editor_absoluteY="0dp">
     
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:orientation="vertical"
                android:paddingLeft="24dp"
                android:paddingRight="24dp"
                android:paddingTop="56dp">
     
                 <ImageView
                    android:id="@+id/imageView3"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    app:srcCompat="@drawable/ic_tiffa" />
     
                <TextView
                    android:id="@+id/textView5"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:text="DON DE SANG"
                    android:textColor="@color/colorPrimary"
                    android:textSize="30dp"
                    android:textStyle="bold"
                    tools:layout_editor_absoluteX="128dp"
                    tools:layout_editor_absoluteY="16dp" />
     
                <TextView
                    android:id="@+id/textView6"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:text="DONNER LA VIE"
                    android:textStyle="bold"
                    android:textSize="24dp"
     
                    tools:layout_editor_absoluteX="138dp"
                    tools:layout_editor_absoluteY="45dp" />
     
                <EditText
                    android:id="@+id/editTextPseudo"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="Pseudo"
                    android:inputType="text"
                    android:textColor="@color/colorPrimary"
                    android:textSize="14sp" />
     
     
     
                <EditText
                    android:id="@+id/input_phone"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="téléphone"
                    android:inputType="phone"
                    android:textColor="@color/colorPrimary"
                    android:textSize="14sp" />
     
                <android.support.v7.widget.AppCompatButton
                    android:id="@+id/buttonlogin"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="24dp"
                    android:layout_marginTop="24dp"
                    android:background="@color/colorPrimary"
                    android:padding="12dp"
                    android:text="Login"
     
                    android:textColor="@color/colorAccent" />
     
                <TextView
                    android:id="@+id/linkSignup"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="24dp"
                    android:gravity="center"
                    android:text="No account yet? Create one"
                    android:textSize="16dip" />
     
            </LinearLayout>
        </ScrollView>

  4. #4
    Membre chevronné
    Profil pro
    Inscrit en
    Octobre 2005
    Messages
    940
    Détails du profil
    Informations personnelles :
    Âge : 44
    Localisation : France

    Informations forums :
    Inscription : Octobre 2005
    Messages : 940
    Points : 1 817
    Points
    1 817
    Par défaut
    Bonjour,

    Avez vous bien importé la classe android.view.View ?

  5. #5
    Membre confirmé
    Avatar de BeeApps
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juillet 2017
    Messages
    86
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 30
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Juillet 2017
    Messages : 86
    Points : 615
    Points
    615
    Par défaut
    Ta méthode viewAll n'est jamais appelé, tu peux le faire à la fin de la méthode onCreate par exemple. Essaye et tiens nous au courant

  6. #6
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Septembre 2012
    Messages
    79
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Niger

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Transports

    Informations forums :
    Inscription : Septembre 2012
    Messages : 79
    Points : 64
    Points
    64
    Par défaut
    BeeApps,j'ai changé de code voici mon login.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
    public class login extends AppCompatActivity {
        DatabaseHelper myDb;
        EditText TextPseudo,Textphone;
        Button blogin;
        View v;
     
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_login);
     
            TextPseudo=(EditText)findViewById(R.id.editTextPseudo) ;
            Textphone=(EditText)findViewById(R.id.input_phone);
     
     
            blogin=(Button)findViewById(R.id.buttonlogin);
            v=findViewById(android.R.id.content);
            blogin.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
     
                    switch (view .getId()) {
                        case R.id.buttonlogin:
                            verifyFromSQLite();
                            break;
                        case R.id.linkSignup:
     
                            Intent intentRegister = new Intent(getApplicationContext(), register.class);
                            startActivity(intentRegister);
                            break;
                }
            }
     
     
     
            private void verifyFromSQLite() {
     
     
                if (myDb.checkInscris(TextPseudo.getText().toString().trim()
                        , Textphone.getText().toString().trim())) {
     
     
                    Intent accountsIntent = new Intent(getApplicationContext(), Menu.class);
                    accountsIntent.putExtra("phone", Textphone.getText().toString().trim());
                    emptyInputEditText();
                    startActivity(accountsIntent);
     
     
                } else {
     
                    Snackbar.make( v,"Pseudo et téléphone incorrect", Snackbar.LENGTH_LONG).show();
                }
            }
            private void emptyInputEditText() {
                TextPseudo.setText(null);
                Textphone.setText(null);
            }
     
     
     
        });
    }

    et le Databasehelper:


    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
    public class DatabaseHelper extends SQLiteOpenHelper {
     
        private static final int DATABASE_VERSION=1;
        private static final String DATABASE_NAME="Donsang.db";
        private static final String TABLE_NAME="Inscription";
        private static final String COLUMN_ID="id";
        private static final String COLUMN_PSEUDO="pseudo";
        private static final String COLUMN_NAME="nom";
        private static final String COLUMN_PHONE="phone";
        private static final String COLUMN_NAISSANCE="naissance";
       private static final String COLUMN_DATEDON="datedon";
       private static final String COLUMN_IMAGE="image";
     
         SQLiteDatabase db;
     
        private static final String TABLE_CREATE="create table Inscription (id integer primary key not null auto_increment,"+
                "pseudo text not null,nom text not null,phone text not null,naissance text not null" +
                "datedon text not null,image Blob";
     
     
          public DatabaseHelper(Context context)
          {
              super(context,DATABASE_NAME,null,DATABASE_VERSION);
     
          }
     
        @Override
        public void onCreate(SQLiteDatabase db) {
     
     
                    db.execSQL(TABLE_CREATE);
            this.db=db;
     
        }
     
        @Override
        public void onUpgrade(SQLiteDatabase db, int i, int i1) {
            String query="DROP TABLE IF EXISTS " + TABLE_NAME;
            db.execSQL(query);
            this.onCreate(db);
     
        }
     
        public boolean insertData(String pseudo,String nom,String phone,String naissance,String datedon,
                                  String image)
        {
     
            SQLiteDatabase db=this.getWritableDatabase();
            ContentValues contentValues=new ContentValues();
            contentValues.put(COLUMN_PSEUDO,pseudo);
            contentValues.put(COLUMN_NAME,nom);
            contentValues.put(COLUMN_PHONE,phone);
            contentValues.put(COLUMN_NAISSANCE,naissance);
     
            contentValues.put(COLUMN_DATEDON,datedon);
     
            contentValues.put(COLUMN_IMAGE,image);
     
          long result=  db.insert(TABLE_NAME,null,contentValues);
            if(result==-1)
                return false;
            else
                return true;
        }
     
     
        public List<Inscription> getAll()
        {
            String[] columns = {
                    COLUMN_PSEUDO,
                    COLUMN_NAME,
                    COLUMN_PHONE,
                    COLUMN_NAISSANCE,
                    COLUMN_DATEDON,
                    COLUMN_IMAGE
            };
     
            String sortOrder =
                    COLUMN_PSEUDO + " ASC";
            List<Inscription> inscritList = new ArrayList<Inscription>();
     
            SQLiteDatabase db = this.getReadableDatabase();
     
            Cursor cursor = db.query(TABLE_NAME, 
                    columns,    
                    null,        
                    null,       
                    null,      
                    null,       
                    sortOrder);
     
            if (cursor.moveToFirst()) {
                do {
                    Inscription user = new Inscription();
                    user.setId(Integer.parseInt(cursor.getString(cursor.getColumnIndex(COLUMN_ID))));
                    user.setPseudo(cursor.getString(cursor.getColumnIndex(COLUMN_PSEUDO)));
                    user.setNom(cursor.getString(cursor.getColumnIndex(COLUMN_NAME)));
                    user.setPhone(cursor.getInt(cursor.getColumnIndex(COLUMN_PHONE)));
                    user.setNaissance(cursor.getString(cursor.getColumnIndex(COLUMN_NAISSANCE)));
                    user.setDate(cursor.getString(cursor.getColumnIndex(COLUMN_DATEDON)));
                    user.setImage(cursor.getBlob(cursor.getColumnIndex(COLUMN_IMAGE)));
     
                    inscritList.add(user);
                } while (cursor.moveToNext());
            }
            cursor.close();
            db.close();
     
     
            return inscritList;
        }
     
     
     
     
     
        public boolean checkInscris(String phone) {
     
     
            String[] columns = {
                    COLUMN_ID
            };
            SQLiteDatabase db = this.getReadableDatabase();
     
     
            String selection = COLUMN_PHONE + " = ?";
     
     
            String[] selectionArgs = {phone};
     
     
            Cursor cursor = db.query(TABLE_NAME, 
                    columns,                  
                    selection,                 
                    selectionArgs,              
                    null,                      
                    null,                     
                    null);                     
            int cursorCount = cursor.getCount();
            cursor.close();
            db.close();
     
            if (cursorCount > 0) {
                return true;
            }
     
            return false;
        }
     
        public boolean checkInscris(String pseudo, String phone) {
     
     
            String[] columns = {
                    COLUMN_ID
            };
            SQLiteDatabase db = this.getReadableDatabase();
     
            String selection = COLUMN_PSEUDO + " = ?" + " AND " + COLUMN_PHONE + " = ?";
     
     
            String[] selectionArgs = {pseudo, phone};
     
     
            Cursor cursor = db.query(TABLE_NAME, 
                    columns,                   
                    selection,                 
                    selectionArgs,             
                    null,                       
                    null,                       
                    null);                     
     
            int cursorCount = cursor.getCount();
     
            cursor.close();
            db.close();
            if (cursorCount > 0) {
                return true;
            }
     
            return false;
        }

    et le manifest!

    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
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.sofari.tiffanezni">
        <uses-permission android:name="android.permission.CAMERA" />
        <uses-feature android:name="android.hardware.camera" />
        <uses-feature android:name="android.hardware.camera.autofocus" />
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
     
        <uses-sdk
            android:minSdkVersion="7"
            android:targetSdkVersion="16" />
        <application
     
            android:allowBackup="true"
            android:icon="@drawable/ic_tiffa"
            android:label="@string/app_name"
            android:roundIcon="@drawable/ic_tiffa"
            android:supportsRtl="true"
            android:theme="@style/AppTheme">
            <activity android:name=".MainActivity">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
     
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
            <activity android:name=".login"
                android:label="Login">
     
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
     
                    <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>
            </activity>
     
     
     
            <activity android:name=".register"
                android:label="Inscription">
     
                <intent-filter>
                <action android:name="android.intent.action.MAIN" />
     
                <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>
            </activity>

    Cette fois-ci je reçois ce message: App has stopped, open again

Discussions similaires

  1. [AC-2007] Bouton de commande : problème clique
    Par nancy54 dans le forum Runtime
    Réponses: 1
    Dernier message: 12/07/2010, 15h43
  2. [C#] problème de bouton transparent
    Par mbibim63 dans le forum Windows Forms
    Réponses: 4
    Dernier message: 17/05/2005, 14h50
  3. Réponses: 24
    Dernier message: 11/01/2005, 10h12
  4. [FLASH MX]Problème de bouton et de _level
    Par Geilgestorm dans le forum Flash
    Réponses: 9
    Dernier message: 01/07/2004, 16h37
  5. Problème de boutons radio
    Par BRAUKRIS dans le forum Composants
    Réponses: 3
    Dernier message: 03/06/2004, 02h41

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