0
我正在Fragments
的Android
上,并且想要以编程方式膨胀我的视图 - 没有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
我该如何解决这个错误?
@Raghunandan。 Broken link –
@Binghammer mods已经删除了这个问题。因此断链 – Raghunandan