Aller au contenu

Problème affichage Fragment


Koal

Recommended Posts

Bonjour à tous!

 

je fais une application androïd avec des fragments dynamiques pour gérer des outils.

 

l'idée est que quand je sélectionne un outil dans le fragment liste.

j'appelle le fragment détail qui va remplacer le FrameLayout et afficher les détails sur l'outil sélectionné.

 

Cependant j'ai un problème d'affichage puisque lorsque je clique sur un outil de la liste, mon fragment détail affiche que les premiers élèments de mon layout.

 

Activity Host de départ

	if (detail_frag != null) {
		    // If article frag is available, we're in two-pane layout...
		
		// Call a method in the ArticleFragment to update its content
			detail_frag.setDetails((int)id);
		
		} else {
			    // If the frag is not available, we're in the one-pane layout and must swap frags...
			


			F_Outils_details detail_frag_new = new F_Outils_details();
			
			Bundle args = new Bundle();
			args.putInt("outil",(int) id);
			detail_frag_new.setArguments(args);
			FragmentTransaction transaction = getFragmentManager().beginTransaction();
//			
			//remplace l'ancien fragment par le nouveau
			transaction.replace(R.id.fragment_container1, detail_frag_new);
			transaction.addToBackStack(null);
			
			// Commit the transaction
			transaction.commit();

Fragment détail

public class F_Outils_details extends Fragment {
	ArrayList detail_outils=new ArrayList();
	Outil outil;
	TextView id_outil;
	TextView designation;
	TextView date_location;
	View a;
	ArrayList liste_outils;
	int mCurrentPosition=-1;
	
	
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
				
		return inflater.inflate(R.layout.f_outils_details, container, false);
		
	}
	

    @Override
    public void onStart() {
        super.onStart();

        // During startup, check if there are arguments passed to the fragment.
        // onStart is a good place to do this because the layout has already been
        // applied to the fragment at this point so we can safely call the method
        // below that sets the article text.
        Bundle args = getArguments();
        System.out.println("DETAIL AVANT TEST");
        //si il y a pas d'arguments
        if (args != null) {

        	setDetails(args.getInt("outil"));
        } else if (mCurrentPosition != -1) {
            System.out.println("mccurent posit");
            // Set article based on saved instance state defined during onCreateView
            setDetails(mCurrentPosition);
        }
    }

	//methode qui va changer le texte !
	public void setDetails(int id){
		if(id==-1){
			designation.setText("");
			date_location.setText("");
		}
		else{
			//on recupere l'outil
			DB_Locoutils dbLocoutils=DB_Locoutils.getInst();
			liste_outils=dbLocoutils.getOutils();
			outil =(Outil) liste_outils.get((int) id);
			System.out.println("**************"+outil.getDesignation());
			
			//id_outil=(TextView) getView().findViewById(R.id.id_outil);
			designation=(TextView) getActivity().findViewById(R.id.designation);
			date_location=(TextView) getActivity().findViewById(R.id.date_location);
			if(designation!=null){
				System.out.println("DESIGNATION OK");
			}
			id_outil.setText(outil.getIdOutil());			
                designation.setText(outil.getDesignation());
		date_location.setText(outil.getDateLocation());
		}
	}

}

layout fragment détail

<?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" >
 <TextView
     android:id="@+id/titre"
     android:layout_width="fill_parent"
   	 android:layout_height="wrap_content"
   	 android:gravity="center"
   	 android:textStyle="bold"
   	 android:textSize="20dp"
   	 android:text="Details" />
 <TextView
     android:id="@+id/id_outil"
     android:layout_width="fill_parent"
   	 android:layout_height="match_parent"
   	 android:text="id outil"
   	  />

<TextView
     android:id="@+id/designation"
     android:layout_width="fill_parent"
   	 android:layout_height="match_parent"
   	 android:text="designation"
   	 />
<TextView
     android:id="@+id/refClient"
     android:layout_width="fill_parent"
   	 android:layout_height="match_parent"
   	 android:text="ref Client"
   	  />
<TextView
     android:id="@+id/date_location"
     android:layout_width="fill_parent"
   	 android:layout_height="match_parent"
   	 android:text="date location"
   	  />
</LinearLayout>

Questions

pourquoi l'affichage déconne? (voir pj)

j'ai déjà testé les variables et l'existence de mes élèments dans mon XML, c'est ok.

 

 

merci d'avance pour l'aide!

Lien vers le commentaire
Partager sur d’autres sites

  • 2 weeks later...
  • 4 weeks later...

Rejoignez la conversation

Vous pouvez poster maintenant et vous enregistrez plus tard. Si vous avez un compte, connectez-vous maintenant pour poster.

Invité
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Répondre à ce sujet…

×   Collé en tant que texte enrichi.   Coller en tant que texte brut à la place

  Seulement 75 émoticônes maximum sont autorisées.

×   Votre lien a été automatiquement intégré.   Afficher plutôt comme un lien

×   Votre contenu précédent a été rétabli.   Vider l’éditeur

×   Vous ne pouvez pas directement coller des images. Envoyez-les depuis votre ordinateur ou insérez-les depuis une URL.

×
×
  • Créer...