Partage
  • Partager sur Facebook
  • Partager sur Twitter

Android Studio : Passer d'une activité à une autre

Sujet résolu
    23 janvier 2020 à 23:10:20

    Bonjour,

    Je viens vers vous car j'ai un petit problème : en effet, j'ai un problème avec le changement d'activité.

    J'ai déjà créé la nouvelle activité et mit en place le OnClick seulement, lorsque la fonction "public void" est demandée pour l'ouvrir, il me marque l'erreur "can't resolve symbol 'Pilotage' " et je suis bloquée dessus ..

    //XAML de la page d'accueil contenant le bouton
    
    <?xml version="1.0" encoding="utf-8"?>
    <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity">
    
        <LinearLayout
            android:id="@+id/linearLayout1"
            android:layout_width="409dp"
            android:layout_height="729dp"
            android:orientation="vertical"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">
    
            <FrameLayout
                android:id="@+id/frameLayout1"
                android:layout_width="match_parent"
                android:layout_height="349dp">
    
                <ImageView
                    android:id="@+id/image"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:contentDescription="@string/image1"
                    app:srcCompat="@drawable/robot" />
            </FrameLayout>
    
            <FrameLayout
                android:id="@+id/frameLayout2"
                android:layout_width="match_parent"
                android:layout_height="match_parent">
    
                <TextView
                    android:id="@+id/textView1"
                    android:layout_width="261dp"
                    android:layout_height="138dp"
                    android:layout_gravity="center"
                    android:text="@string/bonjour_et_bienvenue_sur_l_application"
                    android:textAlignment="center"
                    android:textColor="#3F51B5"
                    android:textSize="30sp"
                    android:textStyle="bold|italic" />
    
                <Button
                    android:id="@+id/button1"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="bottom"
                    android:text="@string/acc_der_aux_commandes"
                    />
            </FrameLayout>
        </LinearLayout>
    </androidx.constraintlayout.widget.ConstraintLayout>
    // Code de la page d'accueil
    
    package com.example.pilotage;
    
    import androidx.appcompat.app.AppCompatActivity;
    
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    
    public class Page_accueil extends AppCompatActivity {
    
        Button button;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_page_accueil);
    
            button = (Button) findViewById(R.id.button1);
            button.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    openPilotage();
                }
            });
        }
    
        public void openPilotage() {
            Intent intent = new Intent(this, Pilotage.class);
            startActivity(intent);
        }
    
    
        }
    //XAML de la deuxième page
    
    <?xml version="1.0" encoding="utf-8"?>
    <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity">
    
        <LinearLayout
            android:id="@+id/linearLayout1"
            android:layout_width="409dp"
            android:layout_height="729dp"
            android:orientation="vertical"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">
    
            <FrameLayout
                android:id="@+id/frameLayout3"
                android:layout_width="match_parent"
                android:layout_height="292dp">
    
                <ImageView
                    android:id="@+id/image2"
                    android:layout_width="328dp"
                    android:layout_height="264dp"
                    android:contentDescription="@string/image2"
                    app:srcCompat="@mipmap/ic_launcher" />
            </FrameLayout>
    
            <FrameLayout
                android:id="@+id/frameLayout4"
                android:layout_width="match_parent"
                android:layout_height="match_parent">
    
            </FrameLayout>
        </LinearLayout>
    </androidx.constraintlayout.widget.ConstraintLayout>

    Merci de votre réponse



    • Partager sur Facebook
    • Partager sur Twitter

    Android Studio : Passer d'une activité à une autre

    × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
    × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
    • Editeur
    • Markdown