Android 安卓碎片赢得';我没有出现

Android 安卓碎片赢得';我没有出现,android,layout,transactions,fragment,screen,Android,Layout,Transactions,Fragment,Screen,嗨,我想展示我创造的片段。我在互联网上搜索任何解决方案,但没有找到任何解决方案 这是我的代码: 这些行调用片段: FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); EditStudent editStudent = new EditStudent(); fragmentTransa

嗨,我想展示我创造的片段。我在互联网上搜索任何解决方案,但没有找到任何解决方案

这是我的代码:

这些行调用片段:

FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
EditStudent editStudent = new EditStudent();
fragmentTransaction.add(editStudent, "editStudent").commit();
EditStudent
扩展
Fragment
。以下是我在
onCreateView
方法中返回的内容:

public class EditStudent extends Fragment
{
    @Override
    public View onCreateView (LayoutInflater inflater,
                          ViewGroup container,
                          Bundle savedInstanceState)
    {
        return inflater.inflate(R.layout.activity_edit_student, container, false);
    }
}
这是我的
活动\u编辑\u学生
布局:

<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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:gravity="left"
android:layoutDirection="ltr"
tools:context="com.nitay.uziel.students.StudentsList"
android:orientation="vertical">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <ImageView
                    android:id="@+id/studentPicture"
                    android:layout_width="120dp"
                    android:layout_height="120dp"
                    android:layout_span="2"/>

            </TableRow>

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Name: "
                    android:textStyle="bold"/>

                <EditText
                    android:id="@+id/studentName"
                    android:layout_width="250dp"
                    android:maxLength="20"
                    android:layout_height="wrap_content"/>

            </TableRow>

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="ID: "
                    android:textStyle="bold"/>

                <EditText
                    android:id="@+id/studentId"
                    android:layout_width="150dp"
                    android:layout_height="wrap_content" />

            </TableRow>

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Phone: "
                    android:textStyle="bold"/>

                <EditText
                    android:id="@+id/studentPhone"
                    android:layout_width="150dp"
                    android:layout_height="wrap_content"
                    android:maxLength="10"/>

            </TableRow>

        </TableLayout>

    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerInParent="true">

        <ImageButton
            android:background="@drawable/cancel"
            android:id="@+id/cancelStudentButton"
            android:layout_height="70dp"
            android:layout_width="70dp"
            android:layout_alignParentRight="true"
            android:layout_marginRight="10dp"
            android:layout_marginBottom="20dp"/>

        <ImageButton
            android:background="@drawable/confirm"
            android:id="@+id/confirmStudentButton"
            android:layout_height="70dp"
            android:layout_width="70dp"
            android:layout_alignParentLeft="true"
            android:layout_marginLeft="10dp"
            android:layout_marginBottom="20dp"/>

    </RelativeLayout>
</FrameLayout>

任何想法都将不胜感激。谢谢。

尝试调用另一个包含片段容器id的方法。例如,
fragmentTransaction.add(R.id.fragmentContainer,editStudent,“editStudent”).commit()

你需要给你的框架布局一个ID,并把片段传递给它

fragmentManager.beginTransaction().add(R.id.fragment_container, editStudent, "editStudent" ).commit();

我发现了问题-FrameLayout应该位于
片段所属的活动

分享你的活动布局我真的不知道:)
fragmentManager.beginTransaction().add(R.id.fragment_container, editStudent, "editStudent" ).commit();