-2
我搜索了很多,但没有得到。我有两个片段 1)表格交易 2)表单交易状态表单交易中有一些字段填充信息和提交按钮。在点击提交我需要浏览一个文件(这是在另一个活动,但相同的片段,即表单交易)。怎么可能在同一片段上有两个活动在同一片段上显示两种不同的激活
我需要创建另一个活动吗?它将延伸到谁?
first fragment with personal information
我搜索了很多,但没有得到。我有两个片段 1)表格交易 2)表单交易状态表单交易中有一些字段填充信息和提交按钮。在点击提交我需要浏览一个文件(这是在另一个活动,但相同的片段,即表单交易)。怎么可能在同一片段上有两个活动在同一片段上显示两种不同的激活
我需要创建另一个活动吗?它将延伸到谁?
first fragment with personal information
一个Fragment
属于主机Activity
,而不是反过来。 Activity
可以承载多个Fragment
。
读取更多的信息文档: 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
。