Android Fragments Part 2

Android Fragments Part 2 – show how to create fragment and what is the method of fragments? How to create UI and How to add the android activity? then what is fragment transaction in Android and how it performs?

1. How to create Fragment?
Following simple steps for fragment creating:
– 1st check the how many fragments you want to use in an activity. Then based on fragments, create classes which will extend the fragment of class.
– Create layout file in XML files
– Use the fragment in your activity.
There are three main methods and these we need to implements fragment
onCreate(): This method is called when fragment is created by android system. By using this method to initialize necessary the components of the fragment that you want to keep when the fragment is paused/stopped and then resumed.
onCreateView(): This method returns view. It is called when the user interface for the fragment needs to be drawn for the first time.
onPause(): When user is leaving the fragment then this method is called. In this method, developer needs to commit any pending changes that need to be brought back when the user resumes.


Leave a Reply

Your email address will not be published. Required fields are marked *