‫We created the adapter class, the fragments and the layouts.
‫Now let's move to the main activity.
‫Joining everything together and running the application.
‫Let's start by creating a Viewpager two instance Viewpager and an adapter from my Viewpager adapter
‫instance.
‫I name it as my adapter.
‫Let's initialize them my adapter equal to new adapter.
‫And here I need to pass two parameters.
‫The first one is the fragment manager and the second parameter is the life cycle.
‫Get support fragment manager and get life cycle.
‫In the previous videos we talked about the get support fragment manager, get support fragment manager
‫as a quick recap is a method that is commonly called within an activity or fragment to obtain an instance
‫of the fragment manager.
‫This instance is used to perform a fragment transaction such as adding, replacing or removing fragments.
‫And as a quick recap for the fragment manager.
‫Fragment manager is a crucial component in Android responsible for managing fragments within an activity.
‫It keeps a track of fragments and their states allowing you to add, remove, replace and interact with
‫fragments.
‫Dynamically get life cycle method.
‫It's often used to obtain a reference to the life cycle of the current component.
‫The Android life cycle is a series of events and the state that an activity or fragment goes through
‫from creation to destruction.
‫It includes method like Oncreate, Onstop, Onresume and others which are called at specific points
‫in the component's lifecycle.
‫The Get life Cycle method returns an instance of the lifecycle class which allows you to observe the
‫life cycle events and respond to them.
‫And as I told you before, you can change the my Viewpager adapter constructor and don't pass the fragment
‫manager or a life cycle.
‫You can choose another format.
‫But it's simple like this get support fragment manager and get lifecycle methods are used.
‫Now let's add the fragments in your Viewpager Fragment adapter class and as a quick recap and to memorize
‫that, we created an array list here called Fragment List in the My Viewpager adapter in order to get
‫a reference and return a fragment for a specific position within the Viewpager.
‫Here the Oncreate fragment method and the get item count using the fragment list dot size.
‫Also, we created an add fragment method in order to allow the user to add more and more fragments later
‫on my adapter.
‫Add the fragment.
‫I'll use this method to add three fragments that I created before I'll create a new fragment.
‫Number one.
‫Also, I'll create my adapter, dot, add fragment and new instance from second adapter fragment number
‫two and my adapter dot add fragment new fragment number three.
‫And by the way, I missed the letter T here in the fragment.
‫Number three, you can add many attributes in the viewpager too, but the most important attribute in
‫the Viewpager two is the orientation Viewpager two instance which I created before equal to find the
‫view by ID or the id dot Viewpager two then Viewpager two dot set orientation Viewpager two dot orientation
‫horizontal or vertical.
‫I'll use horizontal for now.
‫I'll connect the adapter with the Viewpager two exactly as Recyclerview Cardviews as we did before.
‫Viewpager dot set adapter method and I'll pass my adapter.
‫Don't miss this very important step.
‫Save the project and run.
‫And here we go.
‫This is our application displaying fragment number one Fragment.
‫Number two, if we swipe to the left or from right to the left and fragment number three.
‫And you can go back to fragment number one.
‫So congratulations, guys.
‫This is the Viewpager two in Android and this is the latest versions of this Viewpager library.