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/