3

I have fragment A which includes a SwipeRefresh and a RecycleView. When user click on an Item in RecycleView, I replace a new Fragment which is B:

mAdapter.setOnItemClickListener(new MyAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {

                Item tem = mItems.get(position);
                // selected item
                Log.i(TAG, item.getTitle() + " clicked. Replacing fragment.");

                // We start the fragment transaction here. It is just an ordinary fragment transaction.
                getActivity().getSupportFragmentManager()
                        .beginTransaction()
                        .replace(R.id.content_fragment,
                                FragmentB.newInstance(item,
                                        (int) view.getX(), (int) view.getY(),
                                        view.getWidth(), view.getHeight())
                        )
                                // We push the fragment transaction to back stack. User can go back to the
                                // previous fragment by pressing back button.
                        .addToBackStack("detail")
                        .commit();
            }
        });

There is a problem :

When I start to refresh using SwipeRefresh, and it is still running, I click on an item (as you can see the code above), Fragment B will be replaced under Fragment A in the screen. I can see Fragment B under my RecycleView in Fragment A! I am no longer able to scroll in recycleView since onStop() is called in Fragment A and onCreateView is called in Fragment B.

What could be the reason? do you have any workaround?

Addenda : Crash can be reproduce in google sample as well:

https://github.com/googlesamples/android-FragmentTransition/

Ali
  • 9,800
  • 19
  • 72
  • 152

2 Answers2

2

Its a bug. Google may fix it soon.

Issue 78062

Michel Fortes
  • 819
  • 8
  • 12
1

I have met the same question and I even didn't use addToBackStack,at first I think the fragment hasn't been replaced,but I start a new thread and try to find the old fragment by fragmentmanager and find that it has been replaced,I think what you see is not the real fragment,you can regard it as the phantom which the swipe view creates to show an animation.

By coincidence,I find that if you setTransition() for the transaction and it will work properly,maybe the transition animation does the trick.

cajsaiko
  • 1,017
  • 1
  • 8
  • 15
  • Sorry,but I think it is not completely true,I have found another problem,see the comment of this [link](http://stackoverflow.com/a/27073879/4158334) – cajsaiko Apr 23 '15 at 04:33