Bonjour,

J'ai une tâche asynchrone liée a un bouton "Refresh";

J’intègre ma ProgressBar de la façon suivante:
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
<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:background="@color/grey">
         <Button     android:id="@+id/refresh_p"
                    android:text="@string/refresh_promo"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:background="@drawable/custom_button1"/>
 
       <LinearLayout android:id="@+id/linearlayoutProgressBar"
                           android:layout_width="fill_parent"
                           android:layout_height="wrap_content"
                           android:gravity="center"/>
       <ListView
            android:id="@android:id/list"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:listSelector="@color/tabTransparent"
            android:cacheColorHint="#00000000"/>
          <!--   <ListView android:id="@+id/list_promo"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"/>-->
    </LinearLayout>
Et mon AsyncTask :
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
@Override
        protected void onPreExecute() 
        {
            super.onPreExecute();
 
            pb = new ProgressBar(context);
            LinearLayout ll = (LinearLayout) ((Activity) context).findViewById(R.id.linearlayoutProgressBar);
            ll.addView(pb);
            pb.setVisibility(View.VISIBLE);
        }
 
        @Override
        protected void onPostExecute(ArrayList<HashMap<String, String>> promoList) 
        {
            ...
 
            if (pb!=null) 
            {
                pb.setVisibility(View.GONE);
                ((LinearLayout)pb.getParent()).removeView(pb);
            }
        }
Quand j'appuie plusieurs fois sur le bouton "Refresh" et que ma tâche asynchrone n'a pas fini de charger, le problème est que plusieurs ProgressBar s'affichent à l'écran, tout en restant sur la même ligne.

Voici quelques screenshots du rendu:

J'aimerais que la ProgressBar se replace au même endroit.

Quelqu'un saurait-il m'indiquer comment faire ?

Merci d'avance pour votre aide.