Tab Layout with Different Fragments | Learn Android #39

In this video we are going to take a look at the Tab Layout and learn how to open a different Fragment on every new page by overriding the getItem method, instead of providing a different instance of the same Fragment all the time.
I am doing this for you awesome people 💓💓💓
So, please like and subscribe and share for support and help.
Moreover, I reply to every single comment to if you have any question comment it..
Do not forget!

⭐️ ❗ Subscribe to the channel: ⭐️

⭐️ Master Android App: ⭐️

⭐️ Master Flutter App: ⭐️

You don’t need to learn Android/ Java and iOS/ Swift development to build real native mobile apps! Just Click This link and follow the tutorials from zero:

Don’t miss to subscribe by clicking this link:

Never Miss to Like and Subscribe to get latest flutter, android and java tutorials.

⭐️ TAGS ⭐️
android development tutorial,
android programming tutorial,
android app development tutorial,
android tutorial for beginners ,
android app tutorial,
android studio tutorial,
learn android programming ,
android developer tutorial ,
android programming,
android development,
android studio tutorial for beginners,
android course,
android training,
android development course,
android app development course
android studio
android development
android development course
free android app development course
android app development
android tutorial
android (operating system)
product: android
android course
online android course
android online course
android apps
android course trailer
kotlin course
android app tutorial
hack android (full course)
kotlin android
android app development course
make android app
android studio
android tutorial
android studio tutorial
android studio tutorials
android tutorial for beginners
android studio tutorials 2 minutes
android studio tutorials beginners
android studio menu tutorial
admob android studio tutorial
android studio tutorial order food
android studio tutorial for beginners
android (operating system)
android studio for window
android studio
android development
learn android development
learn android programming
learn android
learn android studio
android tutorial
how to learn android app development
android app development
android development course
how to become an android developer
how learn android
how to learn android
learn android scratch
learn android in hindi
make android app
android tutorial for beginners

tablayout tutorial


Xem thêm bài viết khác:


  • Excellent Video Tutorial!! Thanks a lot

    Darklord 7
    Posted July 12, 2020
  • Do you know how to pass an integer data from Activity to Tab layout Fragments on Android Studio….
    plz give answer fast as you can .

    Preet Ojha
    Posted July 12, 2020
  • On PagerAdaptor the line with super(fm); is crossed out 🙁

    Tae Hyung Kwon
    Posted July 12, 2020
  • Thanks Brow

    Akbar Rizaldi
    Posted July 12, 2020
  • When I slide the tab bar doesn't move. it only moves when the tab is clicked.

    Ahnaf Manan
    Posted July 12, 2020
  • public class MyAdapter extends FragmentPagerAdapter {
    private Context myContext;
    int totalTabs;
    public MyAdapter(Context context, FragmentManager fm, int totalTabs) {
    myContext = context;
    this.totalTabs = totalTabs;
    // this is for fragment tabs
    public Fragment getItem(int position) {
    switch (position) {
    case 0:
    DashBoardFrag homeFragment = new DashBoardFrag();
    return homeFragment;
    case 1:
    sellsFragment sportFragment = new sellsFragment();
    return sportFragment;
    case 2:
    CreditFragment movieFragment = new CreditFragment();
    return movieFragment;
    return null;
    // this counts total number of tabs
    public int getCount() {
    return totalTabs;

    // MainActivity

    public class MainActivity extends AppCompatActivity {
    protected void onCreate(Bundle savedInstanceState) {

    TabLayout tabLayout = findViewById(;
    TabItem db = findViewById(;
    TabItem sells = findViewById(;
    TabItem credit = findViewById(;
    final ViewPager viewPager = findViewById(;
    final MyAdapter adapter = new MyAdapter(this,getSupportFragmentManager(), tabLayout.getTabCount());
    viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
    tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
    public void onTabSelected(TabLayout.Tab tab) {
    public void onTabUnselected(TabLayout.Tab tab) {
    public void onTabReselected(TabLayout.Tab tab) {


    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android=""










    Swetabh Suman
    Posted July 12, 2020
  • When I click on the tabs everything is working like in the tutorial however when I swipe the fragment changes but the position of the tab item in the tab layout doesn't

    Dwight K Schrute
    Posted July 12, 2020
  • Thanks excellent tutorial, maybe you could do a tutorial explaining.
    How to add a Swipe View with Tabs in Navigation Drawer

    Alexis Rosero
    Posted July 12, 2020
  • Thanks for your Tutrial, But I Have a problem (java.lang.ClassCastException: androidx.constraintlayout.widget.ConstraintLayout cannot be cast to can your help me please.

    gehad enayat
    Posted July 12, 2020
  • When you tap on the tab fragment changes but when you swipe left or right the tab indicator does not move with the view pager…
    tablayout.setupwithviewpager(viewPager); resolves this problem but this time the Titles of the tabs disappear ..plz help me out

    Kamran Tariq
    Posted July 12, 2020
  • How do we access an item, like a textView in one of the fragment, using findViewById ???

    Chinmay Rao
    Posted July 12, 2020
  • Hi ,First thanks for sharing this useful video
    it wokrs, but I get some problem
    It works when I click the TabItem(ex:chats,status)
    When I slide the page,the page will change,but tabitem won't work
    (ex:when I'm in chats page,I slide the screen,It will change to status,but Tabltem will still at chats)
    Is there anyway to fix this problem?Or I miss anything in your video?
    Thanks again for your great help!

    Posted July 12, 2020
  • Sir how to use tab layout with fragment bottom?

    Vic Vic
    Posted July 12, 2020
  • I have overlapping problem. How to fix ?

    Posted July 12, 2020
  • Hello, I have problem. I see tabs after running program, but not fragments layout (text and colored background). Android studio say that my variables for tabChat etc. are never used and in your video they are yellow and underscored. My are grayed out. What is problem, why I cant see fragments in my tabs ? Thanks.

    Posted July 12, 2020
  • Great tutorial. Can you show us how to add listview with checkboxes in each of these fragment instead of text?

    Posted July 12, 2020
  • First I created ChatFragment, but whenever I am trying to to create one more fragment , ie status fragment and call fragment I am getting error

    Nikitha Bangre
    Posted July 12, 2020
  • PagerAdapater class can't run show error when
    Initialised in mainactivity

    Adapter = new PagerAdapater (getSupportFragmentManager(), Tab layout. getTabCount() ) ;
    This whole line show error
    PagerAdapater is abstract cannot be instantiated

    vikas malik
    Posted July 12, 2020
  • This was amazing, great work !!!!
    Can you do a tutorial where you update this whit some fragment comunication whit activity and other fragmnents, recycle view as a fragment would mean a loot, ty <3 keep up the good work

    petar Prodanovic
    Posted July 12, 2020
  • I have done all the steps but for some reasons when I run the program it keeps stopping and I can't see all the work done! Can you help me figure out why is this happening please?

    Aliaa Abdelrahaman
    Posted July 12, 2020
  • Such an amazing tutorial, it helped me a lot with my project. Can you also please do another tutorial about customizing calendars and how to add events to it, something similar to google calendar.

    Aliaa Abdelrahaman
    Posted July 12, 2020
  • Thanks a lot, I was looking for this tutorial for a long time!!!
    I would appreciate if you will create a tutorial how to scan barcodes with ML Kit on Android.
    Thx again

    Piotr Artman
    Posted July 12, 2020
  • Did not work for my project, do you have an link for code source?Thank you!

    Posted July 12, 2020
  • we recreating fragment classes every time we slide, right ? btw thanks a lot.

    Egemen İnceler
    Posted July 12, 2020
  • Thank you a lot. Just wht i needed. when i sweap tabs (no clicking) the tabs headers wont change selected. any idea? tnks again

    Tomás Chapua Gomes
    Posted July 12, 2020
  • thanks u bro but just if u can put the source code in ur next tutorials it will be more amazing thank u again

    sanshe zakou
    Posted July 12, 2020
  • Keet it up bro👍👍

    yash chaudhary
    Posted July 12, 2020

Leave a comment