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!
🔸LIKE 👍
🔸SHARE ✉
🔸SUBSCRIBE✔

⭐️ ❗ 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
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
android studio tutorial
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
tutorials
android studio tutorial order food
android studio tutorial for beginners
studio
android (operating system)
android studio for window
android
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

#coding
#code
#android
#android_studio
#tutorials
#android_tutorials
#android_lessons
#learn
#learn_android
#learn_coding
#learn_java
#learn_kotlin
#learn_flutter
#tablayout
tablayout tutorial

Nguồn: https://svabc.org/

Xem thêm bài viết khác: https://svabc.org/cong-nghe/

27 Comments

  • 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) {
    super(fm);
    myContext = context;
    this.totalTabs = totalTabs;
    }
    // this is for fragment tabs
    @Override
    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;
    default:
    return null;
    }
    }
    // this counts total number of tabs
    @Override
    public int getCount() {
    return totalTabs;
    }
    }

    // MainActivity

    public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    TabLayout tabLayout = findViewById(R.id.tabMode);
    TabItem db = findViewById(R.id.dashboard);
    TabItem sells = findViewById(R.id.sales);
    TabItem credit = findViewById(R.id.credit);
    final ViewPager viewPager = findViewById(R.id.viewpager);
    final MyAdapter adapter = new MyAdapter(this,getSupportFragmentManager(), tabLayout.getTabCount());
    viewPager.setAdapter(adapter);
    viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
    tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
    @Override
    public void onTabSelected(TabLayout.Tab tab) {
    viewPager.setCurrentItem(tab.getPosition());
    }
    @Override
    public void onTabUnselected(TabLayout.Tab tab) {
    }
    @Override
    public void onTabReselected(TabLayout.Tab tab) {
    }
    });

    }
    }
    //

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">
    <com.google.android.material.tabs.TabLayout
    android:id="@+id/tabMode"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <com.google.android.material.tabs.TabItem
    android:id="@+id/dashboard"
    android:layout_width="wrap_content"
    android:text="DashBoard"
    android:layout_height="wrap_content">

    </com.google.android.material.tabs.TabItem>

    <com.google.android.material.tabs.TabItem
    android:id="@+id/sales"
    android:layout_width="wrap_content"
    android:text="Seles"
    android:layout_height="wrap_content">

    </com.google.android.material.tabs.TabItem>

    <com.google.android.material.tabs.TabItem
    android:id="@+id/credit"
    android:layout_width="wrap_content"
    android:text="Credit"
    android:layout_height="wrap_content">

    </com.google.android.material.tabs.TabItem>

    </com.google.android.material.tabs.TabLayout>

    <androidx.viewpager.widget.ViewPager
    android:id="@+id/viewpager"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    </androidx.viewpager.widget.ViewPager>

    </LinearLayout>

    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 com.google.android.material.tabs.TabLayout) 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 ?https://imgur.com/a/odeKD0W

    Tomislav
    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.

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

    Tomislav
    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

    Like
    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!

    Vader
    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