0

Sorry, I am new to Fragments. I am using a Fragment like this:

<fragment    
    android:name="com.example.lesson1.Fragment1"
    android:id="@+id/activity_fragment1"
    android:layout_weight="1"
    android:layout_width="0px"
    android:layout_height="match_parent"
 />

I know the name attribute reference to a class in src folder, but:
- What exactly the attribute android:name="com.example.lesson1.Fragment1" does here?
- What is its usage?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Sal-laS
  • 11,016
  • 25
  • 99
  • 169

1 Answers1

2

Quoting docs.

The android:name attribute in the <fragment> specifies the Fragment class to instantiate in the layout.

When the system creates this activity layout, it instantiates each fragment specified in the layout and calls the onCreateView() method for each one, to retrieve each fragment's layout. The system inserts the View returned by the fragment directly in place of the element

This is when you declare fragment in xml.

You may also be interested to check this apart from the above.

Activity Layout: Fragment class: vs android:name attributes

Community
  • 1
  • 1
Raghunandan
  • 132,755
  • 26
  • 225
  • 256