Android 片段内部的框架布局
我在一个片段中工作。它包含2个按钮和一个框架布局:Android 片段内部的框架布局,android,android-fragments,Android,Android Fragments,我在一个片段中工作。它包含2个按钮和一个框架布局: <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="fragments.Frag
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="fragments.Fragment_Book_A_Cam">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2">
<Button
android:id="@+id/bt_Public"
android:layout_width="0dp"
android:layout_height="60dp"
android:layout_weight="1"
android:background="@drawable/red"
android:text="Public Jobs "
android:textColor="#FFFFFF" />
<Button
android:id="@+id/bt_Active"
android:layout_width="0dp"
android:layout_height="60dp"
android:layout_weight="1"
android:background="@drawable/black"
android:text="Active Jobs"
android:textColor="#FFFFFF" />
</LinearLayout>
<FrameLayout
android:id="@+id/Fragment_Jobs_BookACam"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
</LinearLayout>
首先,请更正xml文件中存在的错误,并尝试fragmentTransaction的replace()方法,而不是add()。您似乎从未使用过
Fragment\u Jobs\u BookACam
FrameLayout id
如果要在片段中显示片段,则需要使用该方法获取子FragmentManager是否可以提供一个示例?
getChildFragmentManager()
bt_Public.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// fragment = new Fragment_MyCloudVideo();
// FragmentManager fragmentManager = ;
// FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
// fragmentTransaction.replace(R.id.Fragment_MyVideos, fragment);
// fragmentTransaction.commit();
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
Fragment_Public_Jobs fragment = new Fragment_Public_Jobs();
fragmentTransaction.addToBackStack("xyz");
fragmentTransaction.hide(Fragment_Book_A_Cam.this);
fragmentTransaction.add(android.R.id.content, fragment);
fragmentTransaction.commit();
}
});