Android

Android Fragments

Android Fragments

A fragment is a part of an activity that allows the modular design of an activity. A fragment comes with its own layout and behavior. A single fragment can also be used for multiple activities.
To create a fragment, you need to extend the Fragment class and after that, you can add your activity layout to that fragment after its declaration. The activity layout is declared inside the <fragment> tag. 

  • The first step for creating fragments includes gathering requirements such that you need to find the number of fragments required to handle various modes of a device. 
  • Next, you need to create or extend a fragment class based on the number of fragments you require. 
  • After that, layout files are created for each fragment that will contain the layouts for our defined fragments.
  • Lastly, you need to modify the activity by defining the actual logic of replacing fragments. 

Top course recommendations for you

    Arduino vs Raspberry Pi
    2 hrs
    Beginner
    5.5K+ Learners
    4.56  (291)
    DevOps Landscape
    2 hrs
    Beginner
    2.2K+ Learners
    4.51  (71)
    Joins in SQL
    2 hrs
    Beginner
    8K+ Learners
    4.47  (281)
    Introduction to Firewall
    1 hrs
    Beginner
    20.6K+ Learners
    4.55  (1072)
    Design Thinking for Beginners
    1 hrs
    Beginner
    11.8K+ Learners
    4.41  (781)
    Database Management System
    1 hrs
    Beginner
    29.5K+ Learners
    4.44  (2037)
    Operational Excellence and Critical Thinking
    1 hrs
    Beginner
    5.6K+ Learners
    4.49  (263)
    .NET Fundamentals
    2 hrs
    Beginner
    19.5K+ Learners
    4.46  (1006)
    .NET OOPS
    1 hrs
    Beginner
    5.2K+ Learners
    4.55  (223)
    Python Practice Codes
    1 hrs
    Beginner
    6.7K+ Learners
    4.32  (215)