片段没有在第二次android正确替换

时间:2017-02-18 12:15:39

标签: android fragment

我正在使用包含recylerview的FragmentDetail.java文件,当触摸recylerview时,调用相同的片段FragmentDetail.java,当我通过触摸两个同时的recyler视图项重复4次5次时,同样的过程。它不会立即显示后面的片段。相反它显示了recyler视图项的片段。第一个Fragmet包含recylerview,单击ProductMenu调用,在Product菜单recyler视图上单击FragmentDetail.java调用。所以我知道我的问题是什么新闻片段没有得到正确替换。下面是我的代码: -

FirstFragment

list_recycler.addOnItemTouchListener(new RecyclerTouchListener(getActivity(), list_recycler, new ClickListener() {
            @Override
            public void onClick(View view, int position) {
                Fragment fragment = new ProductMenu();

                fragmentManager = getActivity().getSupportFragmentManager();


                fragmentTransaction = fragmentManager
                        .beginTransaction();
                fragmentTransaction.setCustomAnimations(R.anim.slide_in, R.anim.slide_out, R.anim.slide_enter, R.anim.slide_exit);
                fragmentTransaction.replace(R.id.container_body, fragment);
                fragmentTransaction.addToBackStack(null);
                fragmentTransaction.commit();

        }

ProductMenu.java

Also contains the same code.In spite of fragment FragmentDetail fragment = new FragmentDetail();

FragmentDetail.java

FragmentDetail fragment = new FragmentDetail();
                ProductsBean productsBean = arr_related_product.get(position);              

                fragmentManager = getActivity().getSupportFragmentManager();
                //final int newBackStackLength = fragmentManager.getBackStackEntryCount() +1;
                fragmentTransaction = fragmentManager
                        .beginTransaction();
                fragmentTransaction.setCustomAnimations(R.anim.slide_in, R.anim.slide_out, R.anim.slide_enter, R.anim.slide_exit);
                fragmentTransaction.replace(R.id.container_body, fragment);
                fragmentTransaction.commit();

1 个答案:

答案 0 :(得分:0)

你是什​​么意思 : 当我通过触摸两个同时的recyler视图项目重复4次5次时的相同过程。 - > ?

首先我会建议做

 fragmentTransaction.add(R.id.container_body, fragment);

而不是

   fragmentTransaction.replace(R.id.container_body, fragment);

Let me know if it works ,also try to explain your problem little more with help of code