android - 如何在 fragment 中启动 fragment/Activity ?

标签 android android-fragments android-fragmentactivity

enter image description here

我在Fragment中有一个按钮。单击 Button 时,它必须在 Fragment 中打开新的 Fragment/Activity。我已经使用 Intent 编写了代码, Intent i = new Intent(); i.setClass(getActivity(), UpdateProfile.class); 启动 Activity (i); 但它在新 Activity 中开放,如下图所示。 enter image description here

我的要求如图1所示。有人可以建议我该怎么做吗?

编辑:根据 rai 和 ADK 的建议,它工作正常,但新 fragment 覆盖在旧 fragment 上。请参见下图。 “更改密码”(TextView) 是覆盖在现有 fragment 上的新 fragment 。

enter image description here

最佳答案

尝试:

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/

相关文章:

java - 在 BT 适配器关闭时强制停止 LE 扫描会出现 java.lang.IllegalStateException(在 NEXUS 5 和 Android 6 中)

使用 fragment 的 Android 功能区菜单

android - 当应用程序在后台时,ViewPager fragment 被破坏?

Android 良好的 Activity/Fragment 通信实践 - GPS

android - 查询安卓市场

java - 如何在 Android 中使用自定义正则表达式验证 EditText 输入?

android - 将部分数据库模型从服务器同步到客户端

android - 使用兼容包 android 膨胀 fragment

android - Intent extra 返回 null

android - Fragment.isAdded() 在 support-v4 :23. 4.0 中的行为与之前的版本不同