Mettre un fragment dans une activity
Bonjour,
Oui, j'ai déjà suivi le tutoriel sur les Fragment, ainsi que d'autres comme la documentation Android, mais tout cela reste flou. Comment appeler simplement un Fragment dans mon Activity ?
J'ai une Activity, vide, et un xml :
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| public class OpenFragment extends Activity{
// private MainPagerActivity mainpageractivity;
public void onCreate(Bundle savedInstanceState) {
// Create new fragment and transaction
super.onCreate(savedInstanceState);
setContentView(R.layout.openfragment);
}
} |
Code:
1 2 3 4 5
| <fragment android:name="egingenierie.mfm.PlaylistListFragment"
android:id="@+id/list"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent" /> |
Celle-ci n'ayant que pour seul but d'appeler le Fragment qui correspond.
Comment dois-je faire ? les explications et les exemples du tutoriel reste flous a me yeux, mais c'est surement parce que je débute.
Merci pour votre aide ! :)
Problème pour afficher un Fragment depuis un FragmentActivity
Bonjour,
En cliquant sur un Bouton, cela ouvre un FragmentActivity.
Depuis celui-ci j'aimerai afficher un Fragment.
voici les codes :
Le FragmentActivity :
Code:
1 2 3 4 5 6 7 8 9
| public class GoOnPlaylist extends FragmentActivity {
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.goonplaylist);
}
} |
Son Layout :
Code:
1 2 3 4 5 6 7 8 9
| <?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/goonplay"
android:name="egingenierie.mfm.PlaylistListFragment"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
class="egingenierie.mfm.PlaylistListFragment" >
</fragment> |
et le Fragment :
Code:
1 2 3 4 5 6 7 8 9 10
| public class PlaylistListFragment extends Fragment implements StreamUpdaterCallback {
....
...
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.playlist_fragment, container, false);
...
} |
et son Layout :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| <?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" >
<ListView
android:id="@+id/listView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
>
</ListView>
</LinearLayout> |
Quand je clique cela ForceClose, puis voila le message d'erreur:
Code:
07-12 10:02:35.175: E/AndroidRuntime(14161): java.lang.RuntimeException: Unable to start activity ComponentInfo{egingenierie.mfm/egingenierie.mfm.GoOnPlaylist}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
Voila le problème, Merci pour votre aide !
Ps : On m'a déjà demandé de vérifier si le nom de class appelé dans le xml était juste, et il l'est.