Comment mettre en œuvre d'afficher et de masquer fragment à l'intérieur du fragment dans android

Comment mettre en œuvre d'afficher et de masquer fragment à l'intérieur du fragment dans Android? J'ai ajouté deux fragment à l'intérieur de l'activité. Un fragment contenant le menu et un fragment de contenir des sous menu. J'ai beaucoup de bouton dans le menu fragment comme à la maison, idée, etc. Si je clique sur l'idée bouton. J'ai pour afficher le sous-menu. Si j'ai de nouveau cliquez sur l'idée bouton, je dois cacher le sous-menu. Quelqu'un peut-il fournir exemple, ou comment accéder à un point de vue fragment dans un autre fragment?

c'est ma mise en page principale

?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<fragment class="com.gcm.fragment.CommonFragment"
            android:id="@+id/the_frag"
            android:layout_width="wrap_content"
            android:layout_height="match_parent" />  
 <fragment class="com.gcm.fragment.SubFragment"
            android:id="@+id/the_frag1"
            android:layout_marginTop="130dip"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />             


</LinearLayout>

Dans Mon fragment

package com.gcm.fragment;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.TextView;
public class CommonFragment extends Fragment implements OnClickListener {
TextView txtIhaveIdea=null;
boolean menuVisible=false;
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { 
ViewGroup layout = (ViewGroup) inflater.inflate(R.layout.collapsed_menu2, container, false); 
txtIhaveIdea=(TextView)layout.findViewById(R.id.txtIhaveAnIdea);
txtIhaveIdea.setOnClickListener(this);
return layout; 
}
@Override
public void onClick(View v) {
//TODO Auto-generated method stub
if(!menuVisible)
{
FragmentManager fm = getFragmentManager(); 
FragmentTransaction ft = fm.beginTransaction(); 
fm.beginTransaction(); 
Fragment fragOne = new SubFragment(); 
ft.show(fragOne);
}
else
{
FragmentManager fm = getFragmentManager(); 
FragmentTransaction ft = fm.beginTransaction(); 
fm.beginTransaction(); 
Fragment fragOne = new SubFragment(); 
ft.hide(fragOne);   
}
} 
}

Grâce

InformationsquelleAutor kumar | 2011-12-08