Je travaille sur Fragments
dans Android
et voudrais gonfler par programmation ma vue - sans le LayoutInflater
. Dans mon class
, qui extends Fragment
, je voudrais faire quelque chose de base, comme ceci:Comment créer une vue fragmentée sans la mise en page?
@Override
public View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
return new View(inflater.getContext());
}
Cependant, dans mon FragmentActivity
avec cette méthode onCreate:
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
et ce 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>
Je reçois une erreur avec la disposition:
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
Que dois-je faire pour corriger cette erreur?
@Raghunandan. Lien brisé –
@Binghammer mods ont supprimé la question. d'où le lien brisé – Raghunandan