Well, i got a simple <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" />
Then in my code, i added a Fragment to it:
FragClass aFrag = new FragClass();
getSupportFragmentManager().beginTransaction()
.replace(R.id.FragmentContainer, aFrag).commit();
And somewhere else in my code, i want to get that FragClass (extends Fragment)
object from the ID R.id.FragmentContainer
.
i have tried
((ViewGroup) findViewById(R.id.FragmentContainer)).getChildAt(0)
or
((FrameLayout) findViewById(R.id.FragmentContainer)).getChildAt(0)
but they are returning the View
, instead of the Fragment
attached to it.
i know i can keep the variable aFrag
somewhere, so i do not need to find it again. But i believe there should be a way to retieve it.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…