英文:
Recreate Fragment from parent Activity
问题
我需要重新创建一个来自其父 Activity 的片段。我找到的解决方案都是 10 年前的,而且是用 Java 写的。有没有一种简洁的方法,不需要太多样板代码来实现类似这样的功能?
例如从 Activity 中:
getFragments().recreate()
到目前为止,我尝试了不同的解决方案,但都无法使其正常工作。有没有一种方法可以做到这一点?
英文:
I need to recreate a fragment from its parent Activity. The solutions I found were all 10 years old and in Java. Is there a neat way without too much boiler plate to implement something like this?
Like from Activity:
getFragments().recreate()
I have tried different solutions so far but have not been able to make it work. Is there a way to do this?
答案1
得分: 0
我需要从其父活动重新创建一个片段。
只需用新实例替换它:
fragmentManager.commit { replace(idOfFragmentToReplace, MyFragment.create(...)) }
或者,你可以重新创建整个活动。
英文:
> I need to recreate a fragment from its parent Activity.
Just replace it with a new instance:
fragmentManager.commit { replace(idOfFragmentToReplace, MyFragment.create(...)) }
Or you could recreate the whole Activity.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论