2012-11-12 35 views
0

我正在FragmentsAndroid上,并且想要以编程方式膨胀我的视图 - 没有LayoutInflater。在我class,这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 

我该如何解决这个错误?

+0

@Raghunandan。 Broken link –

+0

@Binghammer mods已经删除了这个问题。因此断链 – Raghunandan

回答

-1

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

相关问题