【问题标题】:Going to another Fragment while in a Fragment在 Fragment 中转到另一个 Fragment
【发布时间】:2013-05-12 15:43:07
【问题描述】:

嗨,在我的 Fragment Activity 中,我可以控制我希望我的 Fragment 在哪个页面上,如下所示

mIndicator.setCurrentItem(mAdapter.getCount() - 1);

但是在我的片段中,我想进入另一个片段,我意识到这段代码不起作用,有没有解决这个问题的方法?

【问题讨论】:

  • 您想要从一个片段移动到另一个片段(初始片段不可见)还是在第一个片段之上打开第二个片段?

标签: android eclipse fragment android-fragmentactivity


【解决方案1】:

请在您提出问题时更加具体。当我们不知道您的代码是如何编写的时,很难回答..

首先您必须阅读此内容:http://developer.android.com/guide/components/fragments.html,它将教您 Android 中 Fragment 的基础知识。

无论如何,如果我理解正确,您需要一个FrameLayout 来满足要求。下面的例子:

<FrameLayout 
    android:id="@+id/frameLayout"
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" />

其次,在您的 Java 代码中,您需要输入以下内容:

Fragment mfragment = new yourDummyFragment();

FragmentManager fragmentManager = getSupportFragmentManager(); // The support android library
FragmentTransaction mtransaction = fragmentManager.beginTransaction(); // Initialize the    transaction
mtransaction.replace(R.id.xmlOfYourFragment, mfragment);
mtransaction.commit(); // The change starts.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-19
    • 2013-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-19
    相关资源
    最近更新 更多