Android TextView未在片段布局中添加

Android TextView未在片段布局中添加,android,android-layout,android-fragments,Android,Android Layout,Android Fragments,我有一个关于碎片的主细节活动。我尝试在细节片段中动态添加TextView。但它并没有增加细节片段布局。但布局显示正确 片段代码: @Override public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) { View rootView = inflater.inflate( R.layout.fragment_configur

我有一个关于碎片的主细节活动。我尝试在细节片段中动态添加
TextView
。但它并没有增加细节片段布局。但布局显示正确

片段代码:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
    View rootView = inflater.inflate(
            R.layout.fragment_configuration_detail, container, false);
    RelativeLayout cdf_detail_part1=((RelativeLayout) rootView.findViewById(
            R.id.cdf_detail_part1));

    Log.i("config", "mItem1->"+mItem1);
    if (mItem1 != null) {
        TextView name_text = (TextView) cdf_detail_part1.findViewById(
                R.id.cdf_tv_name);
        name_text.setText(name);
    }

    return rootView;
}
我的布局XMl文件:

<LinearLayout 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:baselineAligned="false"
    android:orientation="horizontal"
    tools:context="com.x.y.configurations.ConfigurationDetailFragment" >

    <RelativeLayout
        android:id="@+id/cdf_detail_part1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#00FF00" >

        <TextView
            android:id="@+id/cdf_tv_name"
            style="?android:attr/textAppearanceLarge"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

      </RelativeLayout>

    <RelativeLayout
        android:id="@+id/cdf_detail_part2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
         android:background="#0000FF" >
    </RelativeLayout>

</LinearLayout>


可能条件
mItem1
null
,条件结果为
false
TextView name\u text=(TextView)rootView.findViewById(R.id.cdf\u tv\u name);insteadmitem不为空..它有值..确定尝试声明视图textview和具有孔可访问性的相对布局ie:public r global并尝试调试,这样您就可以知道按id查找视图是否返回空值没有textview也不为空..尝试了textview名称\u text=(textview)rootView.findViewById(r.id.cdf\u tv\u name);它只显示在文本视图上,但我有多个文本视图。这是diaplys唯一的第一个文本视图。