【问题标题】:Hi i want to redirect from my actvity to another fragment嗨,我想从我的活动重定向到另一个片段
【发布时间】:2015-11-07 12:01:12
【问题描述】:

这是我从 Viewactvity 重定向到 Fragment_home 的代码(Fragment_Home,已在我的 Mainactivity 中使用)

   Intent intent = new Intent(Viewactivity.this,
                           Fragment_Home.class);

                    String responseMsg = jObj.getString("response");
                    Toast.makeText(getApplicationContext(),
                            responseMsg, Toast.LENGTH_LONG).show();
                    System.out.println("Your" + responseMsg);
             startActivity(intent);

我的 Fragment 是 Fragment_Home ,我没有在 Viewactivity 类中使​​用 Fragment 管理器,所以请你帮我从我当前的活动导航到 Fragment_Home。

【问题讨论】:

    标签: android android-fragments android-fragmentactivity


    【解决方案1】:

    Fragment 不是 Activity 中包含的任何 Activity,因此您可以在其中添加、替换、删除 Fragment,而不是 startActivity。

    • 您可以从片段开始活动,而不是从活动片段开始。
    • 如果需要,只需将片段推入 Activity 中的堆栈。
    • 您还可以将 Fragment 附加到处于活动状态的其他 Activity(即不移除 Fragment,以便您的其他 Activity 可以使用其数据)

    查看详情: http://developer.android.com/reference/android/app/Fragment.html

    【讨论】:

    • 是的,我知道,但是 Fragment_home 已经在我的 Maniactvity 中使用了。但是现在我想从我的另一个 Activity 重定向到这个 Fragment。这可能吗?你能给我一些示例代码吗
    • 检查我更新的答案并且无法以这种方式开始片段尝试根据您的要求在另一个活动中使用它。谢谢
    • 当我尝试运行应用程序时它崩溃了,显示错误为无法找到明确的活动类 {harico.groupdeallast/harico.groupdeallast.Fragments.Fragment_Home};您是否在 AndroidManifest.xml 中声明了此活动?
    • 我有登录页面,所以我的起始活动是 loginactvity,我已经在 android manifest 中定义了它
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-18
    • 1970-01-01
    相关资源
    最近更新 更多