Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Right way to inflate android.support.v4.app.fragment from xml

Please, help.

Which is right?

Like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <android.support.v4.app.fragment
        android:id="@+id/advertListFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:name="com.myapp.fragment.AdvertListFragment"/>

Or like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <fragment
        android:id="@+id/advertListFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:name="com.myapp.fragment.AdvertListFragment"/>

Without prefix "android.support.v4".

P.s. I haven't more details

like image 670
ilw Avatar asked Mar 18 '23 08:03

ilw


1 Answers

Use

<fragment
    ...

inflated in an activity that extends android.support.v4.app.FragmentActivity.

For further details, it's FragmentActivity.onCreateView() that handles the inflation for fragment elements.

like image 78
laalto Avatar answered Apr 25 '23 08:04

laalto