好吧,我有一个简单的<FrameLayout>
:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/FragmentContainer"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
然后在我的代码中,我添加了一个片段:
FragClass aFrag = new FragClass();
getSupportFragmentManager().beginTransaction()
.replace(R.id.FragmentContainer, aFrag).commit();
在我的代码中的其他地方,我想FragClass (extends Fragment)
从 ID 中获取该对象R.id.FragmentContainer
。
我努力了
((ViewGroup) findViewById(R.id.FragmentContainer)).getChildAt(0)
或者
((FrameLayout) findViewById(R.id.FragmentContainer)).getChildAt(0)
但他们返回的是View
, 而不是Fragment
附加的。
我知道我可以将变量保存在aFrag
某个地方,所以我不需要再次找到它。但我相信应该有办法找回它。