Bonjour,
voilà je cherche désespérément à utiliser les fragments dans mon applications mais c'est assez ardu ^^. Voilà j'ai mon appli qui se lance avec une sorte de loader dans un premier temps avec l'affichage d'un fragment et ensuite de l'autre ( logique ^^). Mais voilà j'arrive à afficher la deuxième mais elle se trouve sur la première [:cytrouille].
Voilà mon code pour le replace fragmentactivity
le layout de l'activité
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 import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; public class LoginActivity extends FragmentActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); if(savedInstanceState == null) { Thread welcomeThread = new Thread() { @Override public void run() { try { super.run(); sleep(5000); } catch (Exception e) { } finally { Fragment frag = new LoginPageFragment(); android.support.v4.app.FragmentManager fm = getSupportFragmentManager(); android.support.v4.app.FragmentTransaction fragmentTransaction = fm.beginTransaction(); fragmentTransaction.replace(R.id.fragment_login, frag); fragmentTransaction.commit(); } } }; welcomeThread.start(); } } }
je m'arrache les cheveux car je vois pas comment goupiller ça avec les fragments ^^
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 <RelativeLayout 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:background="@drawable/background" tools:context="com.example.monappli.map.LoginActivity"> <fragment android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/fragment_login" android:name="com.example.monappli.map.LoaderPageFragment" tools:layout="@layout/fragment_loader_page" android:layout_centerVertical="true" android:layout_centerHorizontal="true" /> </RelativeLayout>
Partager