Android:如何使用 Intent 从活动中调用 Fragment 类 [英] Android: How to call Fragment class from activity using Intent
问题描述
我正在尝试使用 Intent 从 Activity 调用 Fragment 类.是否可以实施.请提供您的意见.
I am trying to call a Fragment class from Activity using Intent. Is it possible to implement. Please provide your views.
推荐答案
Fragment
需要由 FragmentActivity
托管,您不能通过 FragmentActivity
添加片段代码>意图代码>.
Fragment
needs to be hosted by a FragmentActivity
, you can't add a fragment via an Intent
.
您需要创建一个 FragmentManager
以将您的片段添加到 FragmentActivity
(或通过 Intent
调用另一个 FragmentActivity
代码> 并在其上添加您的片段).
有关详细信息,请参阅此主题:将片段添加到活动运行时.
You need to create a FragmentManager
to add your fragment in the FragmentActivity
(or call another FragmentActivity
via an Intent
and add your fragment on it).
See this topic for more information: Add a Fragment to an Activity at Runtime.
这篇关于Android:如何使用 Intent 从活动中调用 Fragment 类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!