I am working on Fragments
in Android
and would like to programmatically inflate my view - without the LayoutInflater
. In my class
, which extends Fragment
, I would like to do something basic, like this:
@Override
public View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
return new View(inflater.getContext());
}
However in my FragmentActivity
with this onCreate method:
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
and this 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>
I am getting an error with the layout:
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
What do I need to do to fix this error?