Bonjour,

Une partie de mon application comporte un viewPager avec 3 fragments.

1er problème :
Sur mon fragment de gauche, j'arrive à avoir le résultat après un clique sur un bouton mais dans le fragment de droite aucun résultat sur les cliques d'un bouton.

2ème problème :
Dans le fragment du milieu j'ai un radioGroup avec 3 radioButton et j'effectue un sharedpreferences sur la valeur de l'index du radioButton qui est check.

Je récupère cette valeur dans mon 3ème fragment et affiche un TextView et une image différente selon cette valeur.

Or le résultat ne s'affiche que si je repasse par le fragment de gauche avant d'aller au fragment de droite. Si je fais fragment du milieu > fragment de droite, rien ne s'affiche.

J'ai l'impression de ne récupérer que la vue et pas l'activity associé au fragment.

Voici mon 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
public class TabPagerAdapter extends FragmentStatePagerAdapter {
    public TabPagerAdapter(FragmentManager fm) {
		super(fm);
		// TODO Auto-generated constructor stub
	}
 
	@Override
	public Fragment getItem(int i) {
		switch (i) {
        case 0:
            //Fragment pour Ma commande
            return new MaCommande();
        case 1:
           //Fragment pour le paiement
            return new Paiement();
        case 2:
            //Fragment pour le récapitulatif
            return new ValidationCommande();
        }
		return null;
 
	}
 
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return 3; //No of Tabs
	}
 
 
    }
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
public class Commander extends FragmentActivity {
	ViewPager Tab;
    TabPagerAdapter TabAdapter;
	ActionBar actionBar;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.etapescommande);
 
        TabAdapter = new TabPagerAdapter(getSupportFragmentManager());
 
        Tab = (ViewPager)findViewById(R.id.pager);
        Tab.setOnPageChangeListener(
                new ViewPager.SimpleOnPageChangeListener() {
                    @Override
                    public void onPageSelected(int position) {
 
                    	actionBar = getActionBar();
                    	actionBar.setSelectedNavigationItem(position);                  
                    	}
                });
        Tab.setAdapter(TabAdapter);
 
        actionBar = getActionBar();
        //Enable Tabs on Action Bar
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        ActionBar.TabListener tabListener = new ActionBar.TabListener(){
 
			@Override
			public void onTabReselected(android.app.ActionBar.Tab tab,
					FragmentTransaction ft) {
				// TODO Auto-generated method stub
 
			}
 
			@Override
			 public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
 
	            Tab.setCurrentItem(tab.getPosition());
	        }
 
			@Override
			public void onTabUnselected(android.app.ActionBar.Tab tab,
					FragmentTransaction ft) {
				// TODO Auto-generated method stub
 
			}};
			//Add New Tab
			actionBar.addTab(actionBar.newTab().setText("Ma commande").setTabListener(tabListener));
			actionBar.addTab(actionBar.newTab().setText("Paiement").setTabListener(tabListener));
			actionBar.addTab(actionBar.newTab().setText("Validation").setTabListener(tabListener));
 
    }
 
}
Fragment de droite :

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
public class ValidationCommande extends Fragment  {
 
	private Button ValidationCommande;
	private TextView ModeDePaiement;
	private ImageView ImagePaiement;
	private String Paiement,mail;
 
	private static final String urlcommande = "http://xxxx/xxxx.php";
 
	private static final String TAG_Produit = "produit";
	private static final String TAG_Prix = "prix";
	private static final String TAG_Quantite = "quantite";
 
		 @Override
		    public View onCreateView(LayoutInflater inflater, ViewGroup container,
		            Bundle savedInstanceState) {
 
		        View validationcommande = inflater.inflate(R.layout.validationcommande, container, false);
 
		        SharedPreferences app_preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
		        Paiement = app_preferences.getString("RadioPaiement", "null");
		        Log.i("Valeur radiobutton",Paiement);
		        mail = app_preferences.getString("key", "null");
 
 
		        return validationcommande;
		 	}
 
		 public void onActivityCreated(Bundle savedInstanceState) {
				super.onActivityCreated(savedInstanceState);
				View v= getView();
 
				ModeDePaiement = (TextView) v.findViewById(R.id.RecapPaiement);
 
				ImagePaiement = (ImageView) v.findViewById(R.id.RecapImagePaiement);	
 
		        if(Paiement.equals("0")) {
		        	ModeDePaiement.setText("Carte bancaire");
		        	ImagePaiement.setImageResource(R.drawable.modedepaiement);
		        }
		        else if(Paiement.equals("1")) {
		        	ModeDePaiement.setText("Compte Paypal");
		        	ImagePaiement.setImageResource(R.drawable.paypal);
		        }
		        else if(Paiement.equals("2")){
		        	ModeDePaiement.setText("Chèque");
		        	ImagePaiement.setImageResource(R.drawable.cheque);
		        }
 
 
		        ValidationCommande = (Button)v.findViewById(R.id.ButtonValidationCommande);
 
				ValidationCommande.setOnClickListener(new OnClickListener() {	
					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub		
						//NewCommande task = new NewCommande();
						//task.execute(urlcommande);
						AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
						builder.setTitle("Confirmation");
						builder.setMessage("Annuler la commande ?");
 
						builder.setNegativeButton("Oui", new DialogInterface.OnClickListener() {					
							@Override
							public void onClick(DialogInterface arg0, int arg1) {
								// TODO Auto-generated method stub
								AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
								builder.setTitle("Merci de votre commande !");
								builder.setMessage("Une facture récapitulative a été envoyé à l'adresse email : "+"\n"+mail);
 
								builder.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
 
									@Override
									public void onClick(DialogInterface arg0, int arg1) {
										// TODO Auto-generated method stub
										Intent intent2 = new Intent(getActivity(), MenuPrincipal.class);
							            getActivity().startActivity(intent2);
									}
								});
 
							}
						});
 
						builder.setPositiveButton("Non", new DialogInterface.OnClickListener() {
 
							@Override
							public void onClick(DialogInterface arg0, int arg1) {
								// TODO Auto-generated method stub
 
								Intent intent2 = new Intent(getActivity(), ValidationCommande.class);
					            getActivity().startActivity(intent2);
							}
						});
 
 
					}
 
		        });
 
		 }