替换片段内的片段 - (背后)

时间:2014-12-11 15:39:36

标签: android gridview android-fragments

当我点击我的gridview项时,它应该用新片段替换当前的fragement。它似乎发生但我没有看到新的片段。新片段落后于另一片。

我无法弄清楚它为什么不起作用。

有什么想法吗?

由于

 public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) 
        {             
                    View rootView = inflater.Inflate(Resource.Layout.TypesFragment, container, true);
                    return rootView;
        }

        public override void OnActivityCreated(Bundle savedInstanceState)
                {
                    base.OnActivityCreated(savedInstanceState);

                    typesList = FullDAO.GetTypesOfResto (); 

                    GridView mGridView = Activity.FindViewById<GridView> (Resource.Id.list);
                    mGridView.Adapter = new TypeOfRestoAdapter (Activity, typesList);

                    mGridView.ItemClick += delegate (object sender, AdapterView.ItemClickEventArgs args) {

                        OnGridItemClick((GridView)sender,args.Parent,args.Position,0);
                    };
                }

                public void OnGridItemClick(GridView l, View v, int index, long id)
                {
                    //Get the selected type
                    TypeResto currentTypeResto = typesList[index];

                    // Create a new fragment and a transaction.
                    FragmentTransaction fragmentTx = this.FragmentManager.BeginTransaction();
                    RestoByTypeFragment aDifferentDetailsFrag = new RestoByTypeFragment();
                    aDifferentDetailsFrag.typeId = currentTypeResto.id;

                    // Replace the fragment that is in the View fragment_container (if applicable).
                    fragmentTx.Replace(Resource.Id.types_fragment, aDifferentDetailsFrag);

                    // Add the transaction to the back stack.
                    fragmentTx.AddToBackStack(null);

                    // Commit the transaction.
                    fragmentTx.Commit();
                }

0 个答案:

没有答案