Bonjour,

Après énormément de recherche et plusieurs tentative, je n'arrive toujours pas à résoudre mon probléme.
Je voudrais remplacer un fragment dans un view pager qui posséde un fragmentPagerAdapter

En résumé j'ai 8 pages(fragments) dans mon pageview je voudrais remplacer certaine page par une nouvelle page mais je n'y parviens pas



Voici mon activity
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
 
 package tfe.app.GCR2000_v5;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Vector;
import java.util.concurrent.ExecutionException;
 
 
 
 
 
import Carte.Categorie;
import Carte.SousCategorie;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.View;
import android.widget.HorizontalScrollView;
import android.widget.TabHost;
import android.widget.TabHost.TabContentFactory;
import android.widget.TabHost.TabSpec;
import android.widget.TabWidget;
 
public class AfficherOngletsCategories  extends FragmentActivity implements
TabHost.OnTabChangeListener, ViewPager.OnPageChangeListener   {
 
 
	 	private ProgressDialog pDialog;
 
		private static final String READ_CATEGORIES_URL = "http://192.168.1.30/GCR2000/SelectCategories.php";
		private static final String READ_SOUS_CATEGORIES_URL = "http://192.168.1.30/GCR2000/SelectSousCategories.php";
 
	 	private static final String TAG_NOM = "nom";
	 	private static final String TAG_CATEGORIES_ID = "categorie_id";
	 	private static final String TAG_SOUS_CATEGORIES_ID = "sousCategorie_id";
 
 
 
	 	private Categorie catObjet = new Categorie();
	 	private  ArrayList<HashMap<String,String>> ListCat = null;
 
	 	private SousCategorie SousCatObjet = new SousCategorie();
	 	private ArrayList<HashMap<String,String>> ListSousCat;
	 	private TabHost mTabHost;
		private ViewPager mViewPager;
		private HashMap<String, TabInfo> mapTabInfo = new HashMap<String, AfficherOngletsCategories.TabInfo>();
		private PagerAdapter mPagerAdapter;
		 Boolean flag = false;
Bundle test;
		/**
                 * Maintains extrinsic info of a tab's construct
                 */
		private class TabInfo {
			private String tag;
			private Class<?> clss;
			private Bundle args;
			private Fragment fragment;
 
			TabInfo(String tag, Class<?> clazz, Bundle args) {
				this.tag = tag;
				this.clss = clazz;
				this.args = args;
			}
 
		}
 
		/**
                 * A simple factory that returns dummy views to the Tabhost
                 */
		class TabFactory implements TabContentFactory {
 
			private final Context mContext;
 
			/**
                         * @param context
                         */
			public TabFactory(Context context) {
				mContext = context;
			}
 
			/**
                         * (non-Javadoc)
                         * 
                         * @see android.widget.TabHost.TabContentFactory#createTabContent(java.lang.String)
                         */
			public View createTabContent(String tag) {
				View v = new View(mContext);
				v.setMinimumWidth(0);
				v.setMinimumHeight(0);
				return v;
			}
 
		}
 
		/**
                 * (non-Javadoc)
                 * 
                 * @see android.support.v4.app.FragmentActivity#onCreate(android.os.Bundle)
                 */
		protected void onCreate(Bundle savedInstanceState) {
			super.onCreate(savedInstanceState);
			// Inflate the layout
			setContentView(R.layout.activity_main1);
			flag = false;
			LoadCategories lc= new LoadCategories();
			lc.execute();
			//Thread t = new Thread(new LoadCategories2());
 
		//	t.start();
				//Attend la fin AsynTask  
				try {
					lc.get();
 
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (ExecutionException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				//Lancer après AsynTask
				UpdateOnglet(savedInstanceState);
 
		}
 
 
 
		/**
                 * (non-Javadoc)
                 * 
                 * @see android.support.v4.app.FragmentActivity#onSaveInstanceState(android.os.Bundle)
                 * 
                 */
		protected void onSaveInstanceState(Bundle outState) {
			outState.putString("tab", mTabHost.getCurrentTabTag()); // save the tab selected
			//outState.putSerializable("listCat", ListCat);	
			//outState.putSerializable("listSousCat", ListSousCat); 
			// selected
			super.onSaveInstanceState(outState);
		}
 
		/*
		 * (non-Javadoc)
		 * 
		 * @see android.app.Activity#onRestoreInstanceState(android.os.Bundle)
		 */
		@Override
		protected void onRestoreInstanceState(Bundle savedInstanceState) {
			if (savedInstanceState != null) {
				this.mTabHost.setCurrentTabByTag(savedInstanceState.getString("tab")); // set the tab as per the saved state
				//ListCat = (ArrayList<HashMap<String, String>>) savedInstanceState.getSerializable("listCat");	
				//ListSousCat = (ArrayList<HashMap<String, String>>) savedInstanceState.getSerializable("listSousCat");
			}
			super.onRestoreInstanceState(savedInstanceState);
		}
 
 
		 public void updateJSONdata() {
				//Récupere la liste des catégories
				ListCat = catObjet.updateJSONOnedata(READ_CATEGORIES_URL, TAG_CATEGORIES_ID, TAG_NOM);
				//Récupere la liste des sous-catégories
				ListSousCat = SousCatObjet.updateJSONOnedata(READ_SOUS_CATEGORIES_URL, TAG_CATEGORIES_ID, TAG_NOM, TAG_SOUS_CATEGORIES_ID);
 
 
			}
 
 
		 public void UpdateOnglet(Bundle args){
 
 
			 mTabHost = (TabHost) findViewById(android.R.id.tabhost);
			 mTabHost.setup();
			 TabInfo tabInfo = null;
			 Class<?> mfragment =null;
			 Bundle objetbunble = null;
			 List<Fragment> fragments = new Vector<Fragment>();
			 String catName = null;
 
			 //Boucle les categories
		       for ( int i = 0; ListCat.size() > i; i++){
 
		    	   		//Affectation de la categorie dans l'onglet
		    	   		TabSpec ts = mTabHost.newTabSpec(ListCat.get(i).get(TAG_NOM).toString()).setIndicator(ListCat.get(i).get(TAG_NOM).toString());
		    	   		Boolean flag = true;
 
		    	   		//Boucle des sous-categorie 
			   	   		for(int j = 0; ListSousCat.size() > j; j++){
			   	   			//compare  primary key id avec la foreing key pour déterminer si le fragment associé a l'onglet sera une liste ou un gridlayout
			   	   				if (ListCat.get(i).get(TAG_CATEGORIES_ID).toString().equals(ListSousCat.get(j).get(TAG_CATEGORIES_ID).toString())){
 
			   	   					//Affectation du fragment a l'onglet
			   	   					mfragment = AfficherSousCategories.class;
			   	   					catName = ListCat.get(i).get(TAG_NOM).toString();
			   	   					objetbunble = new Bundle();
			   	   					//Fragment test = null;
		   	   					 	objetbunble.putString("sCsousCatId", ListSousCat.get(j).get(TAG_SOUS_CATEGORIES_ID).toString());
		   	   					 	objetbunble.putString("sousCatId", ListSousCat.get(j).get(TAG_CATEGORIES_ID).toString());
		   	   					 	objetbunble.putString("catId",ListCat.get(i).get(TAG_CATEGORIES_ID));
		   	   					 	objetbunble.putBoolean("flag", flag);
		   	   					 	objetbunble.putString("tag", ListCat.get(i).get(TAG_NOM).toString());
		   	   					 	//args = objetbunble;
		   	   					 	//	fragments.setArguments(objetbunble);
 
			   	   					 break;
 
			   	   				}else{
 
		   	   						//Affectation du fragment a l'onglet
				   	   				mfragment = AfficherListElem.class;
 
					   	   			catName = ListCat.get(i).get(TAG_NOM).toString();
					   	   			//Créer le bundle pour envoyer variable url caatégorie au fragment AfficherListElem
				   	  	    	    objetbunble = new Bundle();
				   	  	    	   //Renvoie l'id de la categorie
				   	  	    	    objetbunble.putString("catId", ListCat.get(i).get(TAG_CATEGORIES_ID));
		   	   					 	objetbunble.putString("tag", ListCat.get(i).get(TAG_NOM).toString());
		   	   					    //args = objetbunble;
 
 
			   	   				}//End if
			   	   		}//End for ListSousCat
 
 
 
			   	   			//	mTabHost.addTab(ts, mfragment, objetbunble);
 
			   	   			//Ajouter le fragment dans le tab
			   	   			AfficherOngletsCategories.AddTab(this, this.mTabHost, ts,
									(tabInfo = new TabInfo(catName, mfragment, args) ) );
			   	   			//Ajouter tag dans map
							this.mapTabInfo.put(tabInfo.tag, tabInfo);
 
							//Ajouter à liste de fragment pour l'adapter
							fragments.add(Fragment.instantiate(this, mfragment.getName()));
							//répérer la position
							//objetbunble.putInt("fragId", fragments.get(i).getId());
 
							//set le bunble dans le frag
							fragments.get(i).setArguments(objetbunble);
		       }//End for listCat
 
		       			   mTabHost.setOnTabChangedListener(this);
 
		       			   //Création de l'adapter
					       this.mPagerAdapter = new PagerAdapter(super.getSupportFragmentManager(), fragments);
					       //this.mPagerAdapter.add(fragments);
					       //mPagerAdapter.notifyDataSetChanged();
 
 
							this.mViewPager = (ViewPager) super.findViewById(R.id.tabviewpager2);
							this.mViewPager.setAdapter(this.mPagerAdapter);
							this.mViewPager.setOnPageChangeListener(this);
 
					       /*Forcer le scrool horizontal
					       TabWidget tw = (TabWidget) findViewById(android.R.id.tabs);
					       LinearLayout ll = (LinearLayout) tw.getParent();
					       HorizontalScrollView hs = new HorizontalScrollView(this);
					       hs.setLayoutParams(new FrameLayout.LayoutParams(
					           FrameLayout.LayoutParams.MATCH_PARENT,
					           FrameLayout.LayoutParams.WRAP_CONTENT));
					       ll.addView(hs, 0);
					       ll.removeView(tw);
					       hs.addView(tw);
					       hs.setHorizontalScrollBarEnabled(false);*/
		 }
 
 
		/**
                 * Add Tab content to the Tabhost
                 * 
                 * @param activity
                 * @param tabHost
                 * @param tabSpec
                 * @param clss
                 * @param args
                 */
		private static void AddTab(AfficherOngletsCategories activity,
				TabHost tabHost, TabHost.TabSpec tabSpec, TabInfo tabInfo) {
			// Attach a Tab view factory to the spec
			tabSpec.setContent(activity.new TabFactory(activity));
			tabHost.addTab(tabSpec);
		}
 
		/**
                 * (non-Javadoc)
                 * 
                 * @see android.widget.TabHost.OnTabChangeListener#onTabChanged(java.lang.String)
                 */
		public void onTabChanged(String tag) {
			// TabInfo newTab = this.mapTabInfo.get(tag);
			int pos = this.mTabHost.getCurrentTab();
			this.mViewPager.setCurrentItem(pos);
 
		}
 
		/*
		 * (non-Javadoc)
		 * 
		 * @see
		 * android.support.v4.view.ViewPager.OnPageChangeListener#onPageScrolled
		 * (int, float, int)
		 */
		int x = 0;
		@Override
		public void onPageScrolled(int position, float positionOffset,
				int positionOffsetPixels) {
			// TODO Auto-generated method stub
			x = position;
 
		}
 
		/*
		 * (non-Javadoc)
		 * 
		 * @see
		 * android.support.v4.view.ViewPager.OnPageChangeListener#onPageSelected
		 * (int)
		 */
		@Override
		public void onPageSelected(int position) {
			// TODO Auto-generated method stub
			this.mTabHost.setCurrentTab(position);
 
			//Faire suivre les onglets avec la pageview
			HorizontalScrollView hv = (HorizontalScrollView)findViewById(R.id.scrool);
			TabWidget tw = (TabWidget)findViewById(android.R.id.tabs);
			int ntabs = ListCat.size();
			int taille = ((tw.getWidth() / ntabs)-(tw.getWidth() / (ntabs*4)));
			if (x < position)hv.scrollBy(taille, 0);
			else hv.scrollBy(-taille, 0);
 
 
		}
 
		/*
		 * (non-Javadoc)
		 * 
		 * @see android.support.v4.view.ViewPager.OnPageChangeListener#
		 * onPageScrollStateChanged(int)
		 */
		@Override
		public void onPageScrollStateChanged(int state) {
			// TODO Auto-generated method stub
 
		}
 
 
		//exemple thread : new thread = new (new updateJSONdata()).start();
		public class LoadCategories2 implements Runnable {
 
			@Override
			public void run() {
				// TODO Auto-generated method stub
				updateJSONdata();
				flag = true;
			}
 
		}
 
		public class LoadCategories extends AsyncTask<Void, Void, Boolean> {
 
			@Override
			protected void onPreExecute() {
				super.onPreExecute();
				pDialog = new ProgressDialog(AfficherOngletsCategories.this);
				pDialog.setMessage("Loading Comments...");
				pDialog.setIndeterminate(false);
				pDialog.setCancelable(true);
				pDialog.show();
			}
 
			@Override
			protected Boolean doInBackground(Void... arg0) {
 
					updateJSONdata();
				return null;
			}
 
			@Override
			protected void onPostExecute(Boolean result) {
				super.onPostExecute(result);
				pDialog.dismiss();
 
 
 
 
 
 
			}
		}
 
	}
voici ma class pageadpter

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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
 
/**
 * 
 */
package tfe.app.GCR2000_v5;
 
import java.util.List;
 
 
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.widget.Toast;
 
/**
 * The <code>PagerAdapter</code> serves the fragments when paging.
 */
public class PagerAdapter extends FragmentPagerAdapter {
FragmentTransaction transaction;
	private List<Fragment> fragments;
    private  Fragment mFragmentAtPos0 ;
 
	/**
         * @param fm
         * @param fragments
         */
 
 
	public PagerAdapter(FragmentManager fm, List<Fragment> fragments) {
		super(fm);
		this.fragments = fragments;
 
	}
	public void add(List<Fragment> fragments){
for (int i = 0; fragments.size() > i; i++){
 
 
			transaction  = fragments.get(i).getFragmentManager().beginTransaction();
 
 
			//mPagerAdapter.getItem(poss).d
			//AfficherSousCategories
 
			transaction.add(R.id.pagercontent, fragments.get(i));
			//transaction.hide(AfficherSousCategories.this);
			//transaction.show(list);
			//getActivity().
			//transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
			//transaction.remove(arg0)
			transaction.addToBackStack(null);
 
			transaction.commit();
			}
	}
	/* (non-Javadoc)
	 * @see android.support.v4.app.FragmentPagerAdapter#getItem(int)
	 */
	@Override
	public Fragment getItem(int position) {
		Log.i("getitem", this.fragments.get(position) + " "+position);
 
			return this.fragments.get(position);
	}
 
 
 
	/* (non-Javadoc)
	 * @see android.support.v4.view.PagerAdapter#getCount()
	 */
	@Override
	public int getCount() {
		return this.fragments.size();
	}
 
 
	public int getItemPosition(Object object) {
		   return POSITION_NONE;
		}
}

Voici le fragment que je veux remplacer, au faite ce fragment créer des boutons en fonction des sous-catégories qu'il existe pour la catégorie sélectionné. Une fois que l'utilisateur
clic sur une sous catégorie ce fragment doit être remplacé par un autre
J'utilisais avant un fragmentTabHost et je remplacer le fragment dans le fragmentLayout realContent et tous fonctionné à merveille mais depuis que j'ai voulu utilisé le view pager, je ne ment sort plus.
Dans le viewpager, je dois obligatoirement remplacer le fragment qui existe dans le fragmentAdapter, mais je ne comprend pas comment faire.



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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
 
package tfe.app.GCR2000_v5;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Vector;
 
 
import Carte.SousCategorie;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.LayoutParams;
import android.util.Log;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TableLayout;
 
 
public class AfficherSousCategories extends Fragment {
	private ProgressDialog pDialog;
 
	// testing on Emulator:
	public  String urlSousCat = "http://192.168.1.30/GCR2000/ListSousCat.php";
	public  String urlListSousCat = "http://192.168.1.30/GCR2000/ListElemSousCat.php";
 
	//private static final String TAG_SUCCESS = "success";
	//private static final String TAG_TITLE = "title";
	 Intent monIntent;
	 Button btn;
	//Type d'envoie JSON
	private static final String TAG_POSTS = "posts";
	// Balise JSON :
	private static final String TAG_ELMENT_ID = "elment_id";
	private static final String TAG_NOM = "nom";
	private static final String TAG_DESCRIPTION = "description";
	private static final String TAG_PRIX = "prix";
	public String TAG = "sousCat";
	private ViewPager mViewPager;
	private PagerAdapter mPagerAdapter;
	//public static final String TAG = "sousCat";
	String sousCatId;
	String sousCategorie_id;
	String catId;
	String url;
	android.support.v7.widget.GridLayout buttonContainer;
	public ArrayList<HashMap<String, String>> nSousCat;
	private ArrayList<HashMap<String,String>> ListSousCat;
	Boolean flag = false;
	AfficherListElem list;
	//String tag;
	FragmentTransaction transaction;
	int poss;
	 public View onCreateView(LayoutInflater inflater, ViewGroup container,
	 			Bundle savedInstanceState) {
 
	 		View view = inflater.inflate(R.layout.grid_sous_categories, container, false);
	 		buttonContainer = (android.support.v7.widget.GridLayout)view.findViewById(R.id.buttonContainer);   
 
				mViewPager = (ViewPager) getActivity().findViewById(R.id.tabviewpager2);
 
	        return view;
	    }
 
 
		public void onStart(){
			super.onStart();
				//transaction.add(R.id.realtabcontent, list);
			if(list !=null){
			//	mViewPager.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, 0, 1));
 
				 transaction = getFragmentManager().beginTransaction();
 
				transaction.show(AfficherSousCategories.this);
				transaction.commit();
			}
		}
 
		public void onStop(){
			super.onStop();
				//transaction.add(R.id.realtabcontent, list);
			if(list !=null){
			//	mViewPager.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, 0, 1));
 
				 transaction = getFragmentManager().beginTransaction();
 
				transaction.hide(list);
				transaction.commit();
			}
		}
 
	@Override
	public void onResume() {
 
		// TODO Auto-generated method stub
		super.onResume();
	      //Objet Bindle qui récupérer les données envoyé de l'activity AfficherongletsCatgories
	 		Bundle objetbunble  = getArguments();
 
	 		catId = objetbunble.getString("catId");
	 	    sousCatId = objetbunble.getString("sousCatId"); 
	 	   TAG = objetbunble.getString("tag"); 
	 	    flag = objetbunble.getBoolean("flag");
	 	   poss = objetbunble.getInt("poss");
	 	    new LoadElements().execute();
 
	}
 
 
	public void updateJSONdata() {
 
			SousCategorie sc = new SousCategorie();
			//La list des éléments parser nElemList = reçois un ArrayList<HashMap<String, String>> avec l'url en paramatre  
			nSousCat = sc.updateListElem(urlSousCat, catId);
 
 
	}
 
 
	/**
         * Inserts the parsed data into the listview.
         */
	private void updateList() {
 
	         float pixels = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 175, getResources().getDisplayMetrics());
 
	         for (int i = 0; nSousCat.size() > i; i++){
	        	 final String nomSouCat = nSousCat.get(i).get("nom").toString();
	        	 btn = new Button(getActivity());
	             btn.setText(nomSouCat);
	             // sousCategorie_id = nSousCat.get(i).get("souscategorie_id").toString();
	             btn.setId(Integer.parseInt(nSousCat.get(i).get("souscategorie_id").toString()));
	             btn.setHeight((int) pixels);
	             btn.setWidth((int) pixels);
 
 
	             btn.setOnClickListener(new View.OnClickListener() {
	                 public void onClick(View v) {
	                     // Perform action on click   
 
 
	                	// monIntent = new Intent(getActivity(), AfficherListElem.class);
	                     Bundle objetbunble = new Bundle();
 
	                	 for (int i = 0; nSousCat.size() > i; i++){
	                		 if (v.getId() == Integer.parseInt(nSousCat.get(i).get("souscategorie_id").toString())){
		                		 objetbunble.putString("sousCatId", nSousCat.get(i).get("souscategorie_id").toString()); 
		                		 Log.i("index dans if for", nSousCat.get(i).get("souscategorie_id").toString());
		                		 break;
 
	                		 }
 
	                	 }
	                	 objetbunble.putBoolean("flag", flag);
 
	                     objetbunble.putString("catId", catId);
 
	                     objetbunble.putString("tag", nomSouCat);
 
 
 
 
 
	                     //Remplacer view pager
	                    // List<Fragment> fragments = new Vector<Fragment>();
	                     //fragments.add(Fragment.instantiate(getActivity(), AfficherListElem.class.getName()));
	                     //fragments.get(0).setArguments(objetbunble);
 
	                    // mPagerAdapter.getItemPosition(object);
 
	                   //  mPagerAdapter = new PagerAdapter(
	                    //		 getActivity().getSupportFragmentManager(), fragments);
							//
	                    // 	mViewPager = (ViewPager)getActivity().findViewById(R.id.tabviewpager2);
							//mViewPager.setAdapter(mPagerAdapter);
	                     /*
	                     FragmentManager manager = getFragmentManager();
	                     FragmentTransaction transaction = manager.beginTransaction();
	                     transaction.replace(R.id.tabviewpager2, list.newInstance(flag, catId, nomSouCat));
	                     transaction.addToBackStack(null);
	                     transaction.commit();
	                     */
	               	    	                 list = new AfficherListElem();
	      					list.setArguments(objetbunble);
	      					transaction  = getFragmentManager().beginTransaction();
                                                transaction.replace(R.id.tabviewpager2, list);  //le  probleme et ici car je ne sais pas quel R.id utilisé ou je mis prend mal
                                                transaction.addToBackStack(TAG);
	      					transaction.commit();
 
	      					//mViewPager.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, 0, 0));
	      					//mPagerAdapter.getItem(poss).d
	      					//AfficherSousCategories
	      					//mViewPager.setAdapter(mPagerAdapter);
 
 
 
	      					//transaction.hide(AfficherSousCategories.this);
	      					//transaction.show(list);
	      					//getActivity().
	      					//transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
	      					//transaction.remove(arg0)
 
	      					//mPagerAdapter.notifyDataSetChanged();
	      					//AfficherSousCategories.this.getView().setVisibility(AfficherSousCategories.this.getView().GONE);
	      					//list.getView().setVisibility(list.getView().VISIBLE);
	                 }
	             });
 
 
	             buttonContainer.addView(btn);
	         }//Bouble for      
 
	}
 
 
 
	public class LoadElements extends AsyncTask<Void, Void, Boolean> {
 
		@Override
		protected void onPreExecute() {
			super.onPreExecute();
			pDialog = new ProgressDialog(getActivity());
			pDialog.setMessage("Loading Comments...");
			pDialog.setIndeterminate(false);
			pDialog.setCancelable(true);
			pDialog.show();
		}
 
		@Override
		protected Boolean doInBackground(Void... arg0) {
			updateJSONdata();
			return null;
 
		}
 
		@Override
		protected void onPostExecute(Boolean result) {
			super.onPostExecute(result);
			pDialog.dismiss();
			updateList();
		}
	}
 
 
 
 
 
}
Le layout

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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
 
 
 
<?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"
    android:orientation="vertical" >
 
 
     <include 
         android:id="@+id/top"
         layout="@layout/barre_info"
         android:layout_width="fill_parent"
   		 android:layout_height="wrap_content"
   		 android:layout_marginBottom="5dp"
   		 android:layout_alignParentTop="true"
   		 android:layout_weight="10"
   		/>
         <!--  -->
 
 
 
 
 
 
   <TabHost
	    android:id="@android:id/tabhost"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/top"
	    >
	    <LinearLayout
	        android:orientation="vertical"
	        android:layout_width="fill_parent"
	        android:layout_height="fill_parent"
	        >
	            <HorizontalScrollView
	                android:id="@+id/scrool"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:fillViewport="true"
                android:scrollbars="none">
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal" />
			</HorizontalScrollView>
 
	        <FrameLayout
	            android:id="@android:id/tabcontent"
	            android:layout_width="0dp"
	            android:layout_height="0dp"
	            android:layout_weight="0"/>
 
	        <android.support.v4.view.ViewPager
			  	android:id="@+id/tabviewpager2"
			  	android:layout_width="fill_parent"
			 	android:layout_height="0dp"
			 	android:layout_weight="1"
			  	/>
	       <FrameLayout
	            android:id="@+id/pagercontent"
	            android:layout_width="fill_parent"
	            android:layout_height="0dp"
	            android:layout_weight="1">
 
 
	       </FrameLayout>
	    </LinearLayout>
	</TabHost>
 
 
    <include 
        android:id="@+id/bottom"
        layout="@layout/boutons_user_standard"
         android:layout_width="wrap_content"
   		 android:layout_height="wrap_content"
   		    android:layout_marginBottom="5dp"
   		    android:layout_alignParentBottom="true"
   		    android:layout_weight="10"/>
         <!--  -->
 
 
 
</RelativeLayout>
Je remercie d'avance toutes les personnes qui prenne la peine de lire mon poste