【问题标题】:Showing two different activites on same fragment在同一个片段上显示两个不同的活动
【发布时间】:2016-11-14 13:20:30
【问题描述】:

我搜索了很多但没有找到的人。我有两个片段 1) 表单交易 2) 表单事务状态在表单事务中有一些字段用于填写信息和提交按钮。在单击提交时,我需要浏览一个文件(该文件在另一个活动上但相同的片段,即表单事务)。怎么可能在同一个片段上有两个活动

我需要创建另一个活动吗?它将扩展到谁?

first fragment with personal information

【问题讨论】:

    标签: android fragment


    【解决方案1】:

    Fragment 属于主机 Activity,而不是相反。一个Activity 可以承载多个Fragments。

    阅读文档以获取更多信息: https://developer.android.com/guide/components/fragments.html

    在您的情况下,您似乎想要实现的是用不同的布局和逻辑替换 Form Transaction Fragment。您可以将其替换为另一个新的 Fragment 本身。

    使用FragmentManager 替换现有的Fragment

    FragmentManager fm = getFragmentManager();
    
    if (fm != null) {
        // Perform the FragmentTransaction to replace the Form Transaction content.
        // Using FragmentTransaction#replace will destroy any Fragments
        // currently inside R.id.fragment_content and add the new Fragment
        // in its place.
        FragmentTransaction ft = fm.beginTransaction();
        ft.replace(R.id.fragment_content, new YourFragment());
        ft.commit();
    }
    

    R.id.fragment_content 更改为Form Transaction Fragment 的占位符,将YourFragment 更改为新创建的Fragment

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多