Partage
  • Partager sur Facebook
  • Partager sur Twitter

Android - Lancer un fragment

Sujet résolu
    8 février 2016 à 23:22:04

    Bonjour,

    Je souhaite via un menu, lancer un fragment BlankFragmentTest :

    package com.example.stphen.broketrip.activity;
    
    import android.content.Context;
    import android.net.Uri;
    import android.os.Bundle;
    import android.support.v4.app.Fragment;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    
    import com.example.stphen.broketrip.R;
    
    /**
     * A simple {@link Fragment} subclass.
     * Activities that contain this fragment must implement the
     * {@link BlankFragmentTest.OnFragmentInteractionListener} interface
     * to handle interaction events.
     * Use the {@link BlankFragmentTest#newInstance} factory method to
     * create an instance of this fragment.
     */
    public class BlankFragmentTest extends Fragment {
        // TODO: Rename parameter arguments, choose names that match
        // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
        private static final String ARG_PARAM1 = "param1";
        private static final String ARG_PARAM2 = "param2";
    
        // TODO: Rename and change types of parameters
        private String mParam1;
        private String mParam2;
    
        private OnFragmentInteractionListener mListener;
    
        public BlankFragmentTest() {
            // Required empty public constructor
        }
    
        /**
         * Use this factory method to create a new instance of
         * this fragment using the provided parameters.
         *
         * @param param1 Parameter 1.
         * @param param2 Parameter 2.
         * @return A new instance of fragment BlankFragmentTest.
         */
        // TODO: Rename and change types and number of parameters
        public static BlankFragmentTest newInstance(String param1, String param2) {
            BlankFragmentTest fragment = new BlankFragmentTest();
            Bundle args = new Bundle();
            args.putString(ARG_PARAM1, param1);
            args.putString(ARG_PARAM2, param2);
            fragment.setArguments(args);
            return fragment;
        }
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            if (getArguments() != null) {
                mParam1 = getArguments().getString(ARG_PARAM1);
                mParam2 = getArguments().getString(ARG_PARAM2);
            }
        }
    
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            // Inflate the layout for this fragment
            return inflater.inflate(R.layout.fragment_blank, container, false);
        }
    
        // TODO: Rename method, update argument and hook method into UI event
        public void onButtonPressed(Uri uri) {
            if (mListener != null) {
                mListener.onFragmentInteraction(uri);
            }
        }
    
        @Override
        public void onAttach(Context context) {
            super.onAttach(context);
            if (context instanceof OnFragmentInteractionListener) {
                mListener = (OnFragmentInteractionListener) context;
            } else {
                throw new RuntimeException(context.toString()
                        + " must implement OnFragmentInteractionListener");
            }
        }
    
        @Override
        public void onDetach() {
            super.onDetach();
            mListener = null;
        }
    
        /**
         * This interface must be implemented by activities that contain this
         * fragment to allow an interaction in this fragment to be communicated
         * to the activity and potentially other fragments contained in that
         * activity.
         * <p/>
         * See the Android Training lesson <a href=
         * "http://developer.android.com/training/basics/fragments/communicating.html"
         * >Communicating with Other Fragments</a> for more information.
         */
        public interface OnFragmentInteractionListener {
            // TODO: Update argument type and name
            void onFragmentInteraction(Uri uri);
        }
    }
    

    Ma classe MainActivity :

    Sa méthode onCreate :

    protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
            setSupportActionBar(toolbar);
    
            DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
            ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                    this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
            drawer.setDrawerListener(toggle);
            toggle.syncState();
    
            NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
            navigationView.setNavigationItemSelectedListener(this);
    
    }


    La fonction qui doit faire appel au fragment :

    @SuppressWarnings("StatementWithEmptyBody")
        @Override
        public boolean onNavigationItemSelected(MenuItem item) {
            // Handle navigation view item clicks here.
            int id = item.getItemId();
    
            if (id == R.id.nav_camera) {
                //Lancer un fragment
    
            } else if (id == R.id.nav_gallery) {
    
    
            } else if (id == R.id.nav_slideshow) {
                // http://stackoverflow.com/questions/25808175/android-fragments-fragments-inside-a-frame-or-other-layouts
                FragmentManager fragmentManager = getSupportFragmentManager();
                FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
                BlankFragmentTest fragment = new BlankFragmentTest();
                fragmentTransaction.add(R.id.drawer_layout, fragment);
                fragmentTransaction.commit();
    
            } /*else if (id == R.id.nav_manage) {
    
            } else if (id == R.id.nav_share) {
    
            } else if (id == R.id.nav_send) {
    
            }*/
    
            DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
            drawer.closeDrawer(GravityCompat.START);
            return true;
        }

    Et mes fichiers XML :

    Activity_main :

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        tools:openDrawer="start">
    
        <fragment
            android:name="com.example.stphen.broketrip.activity.BlankFragmentTest"
            android:id="@+id/fragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    
        <include
            layout="@layout/app_bar_main"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    
        <android.support.design.widget.NavigationView
            android:id="@+id/nav_view"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:fitsSystemWindows="true"
            app:headerLayout="@layout/nav_header_main"
            app:menu="@menu/activity_main_drawer" />
    
    
    
    </android.support.v4.widget.DrawerLayout>
    



    fragment_blank :

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/fragment_test"
        tools:context=".activity.BlankFragmentTest">
    
    
        <ScrollView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:id="@+id/scrollView" >
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">
    
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:weightSum="1">
    
                    <ImageView
                        android:src="@drawable/avatar"
                        android:layout_width="55dp"
                        android:layout_height="149dp"
                        android:id="@+id/photo_profil" />
    
                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="vertical">
    
                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:textAppearance="?android:attr/textAppearanceLarge"
                            android:text="MARTIN Paul"
                            android:layout_gravity="center_horizontal"
                            android:id="@+id/nom" />
    
                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:textAppearance="?android:attr/textAppearanceSmall"
                            android:text="Voyageur"
                            android:layout_gravity="center_horizontal"
                            android:id="@+id/voyageur" />
    
                    </LinearLayout>
    
                </LinearLayout>
    
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textAppearance="?android:attr/textAppearanceLarge"
                    android:text="Voyages réalisés : "
                    android:id="@+id/voyages" />
    
                <ListView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/list_voyages" >
    
                </ListView>
    
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textAppearance="?android:attr/textAppearanceLarge"
                    android:text="A propos du voyageur : "
                    android:id="@+id/infos" />
    
                <ListView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/list_infos" >
    
                </ListView>
    
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textAppearance="?android:attr/textAppearanceLarge"
                    android:text="Notations : "
                    android:id="@+id/notations" />
    
                <ListView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/list_notations" >
    
                </ListView>
    
            </LinearLayout>
    
    
        </ScrollView>
    </FrameLayout>
    



    Lorsque je lance mon application, j'obtient l'erreur suivante : 

    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.stphen.broketrip/com.example.stphen.broketrip.activity.MainActivity}: android.view.InflateException: Binary XML file line #11: Error inflating class fragmen

    Malgré mes recherches sur Google, je n'ai pas trouver la solution à ce problème.

    Quelqu'un à une idée ? à déjà rencontré ce problème ?

    Merci d'avance pour vos réponses :) 

    • Partager sur Facebook
    • Partager sur Twitter
    Anonyme
      8 février 2016 à 23:36:41

      On ne voit pas ta classe MainActivity au complet, mais est-ce qu'elle hérite de FragmentActivity ?
      • Partager sur Facebook
      • Partager sur Twitter
        8 février 2016 à 23:57:45

        Non, elle extends de base de AppCompatActivity

        public class MainActivity extends AppCompatActivity
                implements NavigationView.OnNavigationItemSelectedListener



        • Partager sur Facebook
        • Partager sur Twitter
        Anonyme
          9 février 2016 à 0:01:03

          C'est de là que provient ton problème alors :D

          Ton code en java n'arrive pas à sérialiser (inflate) le <fragment> de ton code XML. Tu dois avoir extends FragmentActivity.

          • Partager sur Facebook
          • Partager sur Twitter
            9 février 2016 à 0:01:52

            Salut, Possible de fournir la stacktrace complète ?

            • Partager sur Facebook
            • Partager sur Twitter
              9 février 2016 à 0:02:54

              Je vois ! Mais le problème étant que si j'enlève le extends de AppCompatActivity je perds l'utilisation de mon menu ...

              Comment faire ?

              De plus apres avoir changer l'heritage comme tu me l'as conseiller, la meme erreur apparait !

              -
              Edité par Stephom 9 février 2016 à 0:05:35

              • Partager sur Facebook
              • Partager sur Twitter
                9 février 2016 à 0:06:35

                La classe AppCompatActivity hérite de la classe FragmentActivity, le soucis ne vient pas de là.

                Peux-tu fournir la stacktrace complète ?

                -
                Edité par rolandl 9 février 2016 à 0:07:06

                • Partager sur Facebook
                • Partager sur Twitter
                  9 février 2016 à 0:06:41

                  FATAL EXCEPTION: main
                                                                     Process: com.example.stphen.broketrip, PID: 19068
                                                                     java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.stphen.broketrip/com.example.stphen.broketrip.activity.MainActivity}: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
                                                                         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2702)
                                                                         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2767)
                                                                         at android.app.ActivityThread.access$900(ActivityThread.java:177)
                                                                         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1449)
                                                                         at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                         at android.os.Looper.loop(Looper.java:145)
                                                                         at android.app.ActivityThread.main(ActivityThread.java:5951)
                                                                         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:1400)
                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
                                                                      Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
                                                                         at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:770)
                                                                         at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
                                                                         at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
                                                                         at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
                                                                         at android.view.LayoutInflater.inflate(LayoutInflater.java:366)
                                                                         at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256)
                                                                         at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
                                                                         at com.example.stphen.broketrip.activity.MainActivity.onCreate(MainActivity.java:52)
                                                                         at android.app.Activity.performCreate(Activity.java:6289)
                                                                         at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
                                                                         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2655)
                                                                         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2767) 
                                                                         at android.app.ActivityThread.access$900(ActivityThread.java:177) 
                                                                         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1449) 
                                                                         at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                         at android.os.Looper.loop(Looper.java:145) 
                                                                         at android.app.ActivityThread.main(ActivityThread.java:5951) 
                                                                         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:1400) 
                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195) 
                                                                      Caused by: java.lang.RuntimeException: com.example.stphen.broketrip.activity.MainActivity@ece51b0 must implement OnFragmentInteractionListener
                                                                         at com.example.stphen.broketrip.activity.BlankFragmentTest.onAttach(BlankFragmentTest.java:84)
                                                                         at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1019)
                                                                         at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1226)
                                                                         at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1328)
                                                                         at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2284)
                                                                         at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:111)
                                                                         at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:314)
                                                                         at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:31)
                                                                         at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:79)
                                                                         at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:740)
                                                                         at android.view.LayoutInflater.rInflate(LayoutInflater.java:813) 
                                                                         at android.view.LayoutInflater.inflate(LayoutInflater.java:511) 
                                                                         at android.view.LayoutInflater.inflate(LayoutInflater.java:415) 
                                                                         at android.view.LayoutInflater.inflate(LayoutInflater.java:366) 
                                                                         at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256) 
                                                                         at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109) 
                                                                         at com.example.stphen.broketrip.activity.MainActivity.onCreate(MainActivity.java:52) 
                                                                         at android.app.Activity.performCreate(Activity.java:6289) 
                                                                         at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119) 
                                                                         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2655) 
                                                                         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2767) 
                                                                         at android.app.ActivityThread.access$900(ActivityThread.java:177) 
                                                                         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1449) 
                                                                         at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                         at android.os.Looper.loop(Looper.java:145) 
                                                                         at android.app.ActivityThread.main(ActivityThread.java:5951) 
                                                                         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:1400) 
                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195) 
                  02-09 00:06:15.048 19068-19068/? I/Process: Sending signal. PID: 19068 SIG: 9
                  
                  • Partager sur Facebook
                  • Partager sur Twitter
                    9 février 2016 à 0:15:10

                    Le soucis est ici :

                    MainActivity@ece51b0 must implement OnFragmentInteractionListener

                    Comme le dit la stacktrace et le commentaire de l'interface, ton Activité doit implémenter l'interface.

                    -
                    Edité par rolandl 9 février 2016 à 0:18:09

                    • Partager sur Facebook
                    • Partager sur Twitter
                      9 février 2016 à 0:19:32

                      Cette interface n'est implémenté nul part dans mon code ...

                      • Partager sur Facebook
                      • Partager sur Twitter
                        9 février 2016 à 0:27:07

                        Ok j'ai reussi, lorsque j'implemente OnFragmentInteractionListener l'application fonctionne.

                        Cependant, lorsque je lance l'application, le fragment est deja visible et est en arriere plan de mon activity_main.xml.

                        Comment dois-je procéder pour que fragment_blank sois visible seulement lors du clic ?

                        • Partager sur Facebook
                        • Partager sur Twitter
                        Anonyme
                          9 février 2016 à 0:29:02

                          S'il est créé en XML, il va apparaître aussitôt que le fichier est sérialisé. Si tu veux répondre à un événement Click, tu devras créer le fragment dynamiquement en JAVA.
                          • Partager sur Facebook
                          • Partager sur Twitter
                            9 février 2016 à 0:31:02

                            Le fragment est positionné en dur dans le layout de ton Activité. Si tu ne veux pas qu'il s'affiche de base,il convient de le retirer du layout et à la place de mettre un "placeholder" comme par exemple un FrameLayout. À l'aide du fragment Manager de ton Activité, tu pourras ensuite placer le fragment à la place du placeholder.

                            -
                            Edité par rolandl 9 février 2016 à 0:40:37

                            • Partager sur Facebook
                            • Partager sur Twitter
                              9 février 2016 à 0:35:22

                              Merci pour vos réponses !

                              rolandl, tu n'aurais pas un exemple de code pour illustrer ta phrase :

                              "À l'aide du fragment Manager de ton Activité, tu pourras ensuite placer la fragment à la place du placeholder"

                              Merci :)

                              • Partager sur Facebook
                              • Partager sur Twitter
                                9 février 2016 à 0:38:19

                                Au moment où tu souhaites faire apparaître ton fragment :// Create new fragment and transaction
                                Fragment newFragment =newExampleFragment();
                                FragmentTransaction transaction = getFragmentManager().beginTransaction();

                                // Replace whatever is in the fragment_container view with this fragment,
                                // and add the transaction to the back stack
                                transaction
                                .replace(R.id.fragment_container, newFragment);

                                // Commit the transaction
                                transaction
                                .commit();
                                • Partager sur Facebook
                                • Partager sur Twitter
                                  9 février 2016 à 0:40:06

                                  Cet exemple vient de la documentation officielle. À noter que dans ton cas vu que tu joues avec les classes de type support, il convient plutôt d'appeler la méthode `getSupportFragmentManager` et d'adapter le reste du code en fonction. Mais l'idée est là :)
                                  • Partager sur Facebook
                                  • Partager sur Twitter
                                  Anonyme
                                    9 février 2016 à 0:40:22

                                    Exemple avec getSupportFragmentManager

                                    rolandl a bien raison. Je n'étais pas assez clair par "créer dynamiquement en java", mais c'est effectivement l'utilisation d'un FrameLayout qui va te permettre d'y arriver.

                                    Voici un exemple :

                                        <FrameLayout
                                            xmlns:android="http://schemas.android.com/apk/res/android"
                                            android:id="@+id/fragment_container"
                                            android:layout_width="match_parent"
                                            android:layout_height="match_parent" />

                                    content_main.xml

                                    Dans l'événement Click 

                                            //Setup fragment
                                    
                                            // Check that the activity is using the layout version with
                                            // the fragment_container FrameLayout
                                            if (findViewById(R.id.fragment_container) != null) {
                                    
                                                // However, if we're being restored from a previous state,
                                                // then we don't need to do anything and should return or else
                                                // we could end up with overlapping fragments.
                                                if (savedInstanceState != null) {
                                                    return;
                                                }
                                    
                                                // Create a new Fragment to be placed in the activity layout
                                                SubscriptionFormFragment firstFragment = new SubscriptionFormFragment();
                                    
                                                // In case this activity was started with special instructions from an
                                                // Intent, pass the Intent's extras to the fragment as arguments
                                                firstFragment.setArguments(getIntent().getExtras());
                                    
                                                // Add the fragment to the 'fragment_container' FrameLayout
                                                getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, firstFragment).commit();
                                            }

                                    MainActivity.java


                                    -
                                    Edité par Anonyme 9 février 2016 à 0:42:30

                                    • Partager sur Facebook
                                    • Partager sur Twitter
                                      9 février 2016 à 0:43:05

                                      Merci !

                                      J'ai donc ce code la :

                                       FragmentManager fragmentManager = getSupportFragmentManager();
                                                  FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
                                                  BlankFragmentTest fragment = new BlankFragmentTest();
                                                  fragmentTransaction.replace(R.id.drawer_layout, fragment);
                                                  fragmentTransaction.addToBackStack(null);
                                                  fragmentTransaction.commit();

                                      Mon fragment apparait bien lors du clic mais comment retirer mon :

                                      <include
                                              layout="@layout/app_bar_main"
                                              android:layout_width="match_parent"
                                              android:layout_height="match_parent" />

                                      Dans activity_main ?


                                      • Partager sur Facebook
                                      • Partager sur Twitter
                                        9 février 2016 à 0:47:39

                                        J'ai en faite des includes dans des includes qui ont été généré automatiquement par Android Studio lors de la création du projet, je suppose que ce code est bon ?

                                        Dans tout les cas voici mes fichiers XML :

                                        <?xml version="1.0" encoding="utf-8"?>
                                        <android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout"
                                            android:layout_width="match_parent"
                                            android:layout_height="match_parent"
                                            android:fitsSystemWindows="true"
                                            tools:openDrawer="start">
                                        
                                        
                                            <include
                                                layout="@layout/app_bar_main"
                                                android:layout_width="match_parent"
                                                android:layout_height="match_parent" />
                                        
                                            <android.support.design.widget.NavigationView
                                                android:id="@+id/nav_view"
                                                android:layout_width="wrap_content"
                                                android:layout_height="match_parent"
                                                android:layout_gravity="start"
                                                android:fitsSystemWindows="true"
                                                app:headerLayout="@layout/nav_header_main"
                                                app:menu="@menu/activity_main_drawer" />
                                        
                                        
                                        
                                        </android.support.v4.widget.DrawerLayout>
                                        

                                        <?xml version="1.0" encoding="utf-8"?>
                                        <android.support.design.widget.CoordinatorLayout 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"
                                            android:fitsSystemWindows="true"
                                            tools:context=".activity.MainActivity">
                                        
                                            <android.support.design.widget.AppBarLayout
                                                android:layout_width="match_parent"
                                                android:layout_height="wrap_content"
                                                android:theme="@style/AppTheme.AppBarOverlay">
                                        
                                                <android.support.v7.widget.Toolbar
                                                    android:id="@+id/toolbar"
                                                    android:layout_width="match_parent"
                                                    android:layout_height="?attr/actionBarSize"
                                                    android:background="#3eb489"
                                                    app:popupTheme="@style/AppTheme.PopupOverlay" />
                                        
                                            </android.support.design.widget.AppBarLayout>
                                        
                                            <include layout="@layout/content_main" />
                                        
                                        </android.support.design.widget.CoordinatorLayout>
                                        
                                        <?xml version="1.0" encoding="utf-8"?>
                                        <LinearLayout 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"
                                            android:orientation="vertical"
                                            android:paddingBottom="@dimen/activity_vertical_margin"
                                            android:paddingLeft="@dimen/activity_horizontal_margin"
                                            android:paddingRight="@dimen/activity_horizontal_margin"
                                            android:paddingTop="@dimen/activity_vertical_margin"
                                            app:layout_behavior="@string/appbar_scrolling_view_behavior"
                                            tools:context=".activity.MainActivity"
                                            tools:showIn="@layout/app_bar_main"
                                            android:id="@+id/content_main">
                                        
                                            <LinearLayout
                                                android:layout_height="0dp"
                                                android:layout_width="match_parent"
                                                android:layout_weight="1"
                                                android:orientation="horizontal">
                                        
                                                <ImageButton
                                                    android:src="@drawable/voyage"
                                                    android:adjustViewBounds="true"
                                                    android:layout_height="match_parent"
                                                    android:layout_width="0dp"
                                                    android:layout_weight="1"
                                                    android:id="@+id/button_voyage"
                                                    android:layout_marginBottom="5dp"
                                                    android:layout_marginLeft="2dp"
                                                    android:layout_marginRight="5dp"
                                                    android:layout_marginTop="5dp"
                                                    android:clickable="true"
                                                    android:onClick="LancerVoyageActivity" />
                                        
                                            </LinearLayout>
                                        
                                        
                                        
                                        
                                        
                                        
                                            <LinearLayout
                                                android:layout_height="0dp"
                                                android:layout_width="match_parent"
                                                android:layout_weight="1"
                                                android:orientation="horizontal">
                                        
                                                <ImageButton
                                                    android:src="@drawable/transport"
                                                    android:adjustViewBounds="true"
                                                    android:layout_height="match_parent"
                                                    android:layout_width="0dp"
                                                    android:layout_weight="1"
                                                    android:id="@+id/button_transport"
                                                    android:layout_marginBottom="5dp"
                                                    android:layout_marginLeft="2dp"
                                                    android:layout_marginRight="5dp"
                                                    android:layout_marginTop="5dp"
                                                    android:clickable="true"
                                                    android:onClick="LancerVoyageActivity" />
                                        
                                            </LinearLayout>
                                        
                                            <LinearLayout
                                                android:layout_height="0dp"
                                                android:layout_width="match_parent"
                                                android:layout_weight="1"
                                                android:orientation="horizontal">
                                        
                                                <ImageButton
                                                    android:src="@drawable/logement"
                                                    android:adjustViewBounds="true"
                                                    android:layout_height="match_parent"
                                                    android:layout_width="0dp"
                                                    android:layout_weight="1"
                                                    android:id="@+id/button_logement"
                                                    android:layout_marginBottom="5dp"
                                                    android:layout_marginLeft="2dp"
                                                    android:layout_marginRight="5dp"
                                                    android:layout_marginTop="5dp"
                                                    android:clickable="true"
                                                    android:onClick="LancerVoyageActivity" />
                                        
                                            </LinearLayout>
                                        
                                            </LinearLayout>
                                        

                                        -
                                        Edité par Stephom 9 février 2016 à 0:49:02

                                        • Partager sur Facebook
                                        • Partager sur Twitter
                                          9 février 2016 à 14:29:26

                                          Merci beaucoup, tout fonctionne :)
                                          • Partager sur Facebook
                                          • Partager sur Twitter

                                          Android - Lancer un fragment

                                          × 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