Bonjour à tous !

Je suis en train de développer une appli, dans laquelle j'utilise un NavigationBar avec donc des Fragments.

Dans mon fragment principal, j'ai intégré une recyclerView qui charge des données web.

Mon souci est que le chargement du fragment complet, et donc de la recyclerView est lent, et rien n'apparaît à l'écran pendant plusieurs secondes (de longues secondes...).

J'ai pensé alors à intégrer une progressBar de forme circulaire pour que l'utilisateur visualise que des données sont en train de se charger. L'idéal serait que le fragment se charge instantanément, que la progressBar apparaissent puis que la recyclerView se charge.

Mais malheureusement je n'arrive pas à intégrer ma progressBar dans mon fragment, je ne sais pas comment procéder. Quelqu'un pourrait-il m'expliquer comment puis-je faire ?

Voici mon code à l'heure actuelle :

Le layout de mon fragment

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
 
<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"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="xxx.MainFragment"
    android:paddingTop="50dp">
 
 
 
    <LinearLayout
 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:background="@drawable/background"
        android:id="@+id/linear_layout" >
 
 
 
        <android.support.v7.widget.RecyclerView
            android:id="@+id/listFeed"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clipToPadding="false"
            android:paddingBottom="16dp"
            android:paddingTop="16dp"
            android:scrollbars="vertical" >
 
        </android.support.v7.widget.RecyclerView>
 
 
    </LinearLayout>
 
 
    <ProgressBar
        android:id="@+id/progress"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:indeterminate="true"
        android:layout_centerInParent="true" />
 
 
 
</RelativeLayout>
Et mon MainFragment :

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
 
public class MainFragment extends Fragment {
 
 
    private AdView adView;
    private RecyclerView recyclerView;
    public static ListFeedAdapter lfa;
 
 
    public MainFragment() {
        // Required empty public constructor
    }
 
 
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_main, container, false);
 
        if (Build.VERSION.SDK_INT > 9) {
            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
            StrictMode.setThreadPolicy(policy);
        }
 
        ArrayList<Feed> feeds = ContainerData.getFeeds();
        for (Feed feed : feeds) {
            Log.e("MainActivity", feed.toString());
        }
 
 
        //RecyclerView
        lfa = new ListFeedAdapter(getActivity(), feeds);
        recyclerView = (RecyclerView) getView().findViewById(R.id.listFeed);
        recyclerView.setAdapter(lfa);
        final LinearLayoutManager llm = new LinearLayoutManager(getActivity());
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        recyclerView.setLayoutManager(llm);
 
 
 
        return rootView;
    }
}
En vous remerciant par avance pour vos réponses ;-)