android-在运行swipeRefresh时,替换片段无法正常工作
作者:互联网
我有片段A,其中包含SwipeRefresh和RecycleView.
当用户单击RecycleView中的项目时,我将替换为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刷新并仍在运行时,我单击一个项目(如您在上面的代码中所见),片段B将替换为屏幕中的片段A.
我可以在片段A的RecycleView下看到片段B!
我不再能够在recycleView中滚动,因为onStop()在片段A中被调用,并且onCreateView在片段B中被调用.
可能是什么原因?你有什么解决方法吗?
附录:崩溃也可以在Google示例中重现:
https://github.com/googlesamples/android-FragmentTransition/
解决方法:
它是一个错误. Google可能会尽快修复它.
标签:android-recyclerview,swiperefreshlayout,android 来源: https://codeday.me/bug/20191120/2044948.html