我在Fragment
中有一个按钮。单击 Button
时,它必须在 Fragment
中打开新的 Fragment/Activity
。我已经使用 Intent
编写了代码,
Intent i = new Intent();
i.setClass(getActivity(), UpdateProfile.class);
启动 Activity (i);
但它在新 Activity 中开放,如下图所示。
我的要求如图1所示。有人可以建议我该怎么做吗?
编辑:根据 rai 和 ADK 的建议,它工作正常,但新 fragment 覆盖在旧 fragment 上。请参见下图。 “更改密码”(TextView
) 是覆盖在现有 fragment 上的新 fragment 。
最佳答案
尝试:
getFragmentManager()
.beginTransaction()
.replace(containerViewId, newFragment)
.addToBackStack(null) // enables back key
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE) // if you need transition
.commit();
关于android - 如何在 fragment 中启动 fragment/Activity ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15969007/