Tab Layout with View Pager 2 in Android | Android Tutorials | Android.

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hey guys welcome back to my youtube channel in this video we will learn how to create dab layout using view pager 2 in android so let's get started first of all go to activitymain.xml remove this textview and make it relative layout add a tab layout that will contain our tabs its width will be match parent and hide will be wrap content give this dab layout an ide [Music] now add a view page or two that will contain fragments inside that its height and width will be match parent set it below the tab layout and also give this view pager an ide now create a new fragment for first app name it first fragment set text as first fragment and align it to parent center [Music] now similarly create two more fragments like this and name them second and third fragment respectively now fragments are added let's create a java class for fragment adapter [Music] it will extends fragment state adapter and this is showing error so click on this red bulb and implement these methods this will give the item count now it's still showing some error so again click on this red bulb and create a constructor select third one now inside create fragment [Music] use switch case statement for selecting fragment according to position if position is 1 return second fragment if position is two return third fragment [Music] else return first fragment now go to main activity take a tab layout also take a view page or two and a fragment adapter [Music] now initialize all views take a fragment manager get support fragment manager now create adapter object and attach this adapter to view pager 2. [Music] now create three new tabs inside tab layout [Music] and name them as first second and third [Music] now add on tab selected listener on tab layout so when we will click on any tablet we'll change the pager fragment also now attach register page change call back to pager two so that if we swipe the pager we can also change the corresponding tab dot slash run your project thanks for watching subscribe for more videos
Info
Channel: Code 2 Develop
Views: 22,172
Rating: 4.9215684 out of 5
Keywords: Android, Java, Android Tutorials, Tab Layout, View Pager 2, Fragments, Github, Git, Whatsapp
Id: 5-RWOvJ9oq8
Channel Id: undefined
Length: 5min 51sec (351 seconds)
Published: Fri Feb 19 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.