Fragment 后台堆栈中的 ListView 仍在调用 getView()
ListView in Fragment backstack still calling getView()
我有一个 Fragment
其中包含 ListView
说 FragmentA
,当我添加另一个包含另一个 ListView
说 FragmentB
的片段时:
getFragmentManager().beginTransaction()
.add(R.id.fragment_container, FragmentB)
.commit()
我注意到 FragmentA
中 ListView
的 getView()
仍然被调用,即使顶部片段现在是 FragmentB
,任何原因以及我如何防止这种行为?
您正在将碎片堆叠在一起。
而不是 add
使用 replace
替换该容器中的任何现有片段。
我有一个 Fragment
其中包含 ListView
说 FragmentA
,当我添加另一个包含另一个 ListView
说 FragmentB
的片段时:
getFragmentManager().beginTransaction()
.add(R.id.fragment_container, FragmentB)
.commit()
我注意到 FragmentA
中 ListView
的 getView()
仍然被调用,即使顶部片段现在是 FragmentB
,任何原因以及我如何防止这种行为?
您正在将碎片堆叠在一起。
而不是 add
使用 replace
替换该容器中的任何现有片段。