0

我正在研究FragmentsAndroid希望以编程方式夸大我的观点 - 没有LayoutInflater. 在我的class, which 中extends Fragment,我想做一些基本的事情,比如:

@Override
public View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) 
{
    return new View(inflater.getContext());
}

但是在我FragmentActivity的这个 onCreate 方法中:

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
}

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />

    <fragment class="edu.self.myFragment" 
        android:id="@+id/titles"
        android:tag="foo"
        android:layout_width="50px"
        android:layout_height="50px" />

</LinearLayout>

我收到布局错误:

11-11 23:25:18.142: E/AndroidRuntime(1162): Caused by: java.lang.IllegalArgumentException: Binary XML file line #12: Duplicate id 0x7f050000, tag foo, or parent id 0x0 with another fragment for edu.self.myFragment

我需要做什么来修复这个错误?

4

1 回答 1

-1

您不能对包含另一个片段中的片段的 xml 进行膨胀。您必须手动添加子片段。

于 2013-07-04T00:15:12.967 回答