Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The android:name attribute in the <fragment>

Please explain ArticleListFragment and ArticleReaderFragmet as they are in this code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <fragment android:name="com.example.news.ArticleListFragment"
            android:id="@+id/list"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="match_parent" />
    <fragment android:name="com.example.news.ArticleReaderFragment"
            android:id="@+id/viewer"
            android:layout_weight="2"
            android:layout_width="0dp"
            android:layout_height="match_parent" />
</LinearLayout>

I don't know what they refer to? Is it either the Fragment class (or its subclass) that use in source code or XML files for layout?

If they are XML files where must they be located?

like image 781
hamid_c Avatar asked Jul 02 '15 13:07

hamid_c


People also ask

How do I get FragmentManager in fragment?

Accessing in a Fragment Inside a fragment, you can get a reference to the FragmentManager that manages the fragment's children through getChildFragmentManager() . If you need to access its host FragmentManager , you can use getParentFragmentManager() .


1 Answers

The ArticleListFragment and ArticleReaderFragment are names of classes that contain java code for these fragments.

As it was mentioned before you can have your fragment inside containing activity, but it is not a good practice to do so.

For a good example try to create "Blank Activity with Fragment" using Android Studio wizard. It will create an activity class and a fragment class along with 2 XML files for activity and fragment respectively.

like image 63
Ivan V Avatar answered Sep 21 '22 22:09

Ivan V