更换片段无法正常工作,而swipeRefresh运行 [英] Replacing Fragment does not work properly while swipeRefresh is running
问题描述
我有片段,其中包括一个SwipeRefresh和RecycleView。
当在一个RecycleView资料的用户点击,我更换一个新的片段,其为B:
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();
}
});
有一个问题:
当我开始使用SwipeRefresh刷新,它仍然在运行,我点击一个项目(因为你可以看到上面的code),片段B将在$代替 C $ C>片段A在屏幕上。
我可以看到片段B我的片段A RecycleView下!
我不再能够因为的onStop()
被称为片段A在recycleView滚动和 onCreateView
被称为片段B点。
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/
推荐答案
它是一个错误。谷歌可能很快修复它。
Its a bug. Google may fix it soon.
这篇关于更换片段无法正常工作,而swipeRefresh运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!