Bonjour, j'ai un petit problème de fragment.
j'ai un layout comme ça :
et j'essaye de remplacer (ou d'ajouter à) "detail_fragment" par un fragment dans mon code java, code:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <include layout="@layout/base_header" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:layout_marginTop="0dp" android:layout_marginLeft="0dp"></include> <LinearLayout android:layout_marginTop="50dp" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" android:id="@+id/linear1"> <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1"> <fragment android:layout_width="match_parent" android:layout_height="match_parent" android:name="package" android:id = "@+id/list_fragment"/> </LinearLayout> <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="3" android:id="@+id/detail_fragment"> </LinearLayout> </LinearLayout> </RelativeLayout>
le problème c'est que j'ai une exception qui me dit que le l'enfant spécifié à déjà un parent et qu'il faut que j'appel removeView() sur le parent d'abord.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); Fragment newFragment = new FragmentDetail(); ft.replace(R.id.detail_fragment, newFragment); ft.addToBackStack(null); ft.commit();
j'ai essayé un add a la place du replace ça me fait la même exception
il y a quelque chose que je fais mal mais je vois pas quelqu'un à une idée?
Partager