Reputation: 7048
I have the following Layout with static fragment and RelativeLayout as parent:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/activity_vertical_margin">
<fragment
android:id="@+id/list_fragment"
android:name="com.listfragmenttest.MyListFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
Yet the container or parent comes up null
in OnCreateView:
public class MyListFragment extends ListFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.my_list_fragment, container, false);
}
}
Is this the normal behavior for Static fragment?
Upvotes: 4
Views: 643
Reputation: 152867
Yes, that's how it is implemented. Fragments inflated statically from XML get a null
as parent container.
For details, consult FragmentManager
source. In particular, onCreateView()
that handles fragment instantiation from layout inflation, setting mInLayout = true
and calls to performCreateView()
that are conditional on mInLayout
.
Upvotes: 1