TAB LAYOUT WITH VIEWPAGER 2 - Android Fundamentals

  Рет қаралды 40,469

Philipp Lackner

Philipp Lackner

4 жыл бұрын

In this video you will learn how to set up a tab layout and swipe through the tabs using the new viewpager2. You will also learn how to respond to tab switch events.
⭐ Get certificates for your future job
⭐ Save countless hours of time
⭐ 100% money back guarantee for 30 days
⭐ Become a professional Android developer now:
pl-coding.com/premium-courses...
💻 Let me personally review your code and provide individual feedback, so it won't backfire and cost you a fortune in future:
elopage.com/s/philipplackner/...
Regular Android tutorials on my Instagram: / philipplackner_official
Checkout my GitHub: github.com/philipplackner

Пікірлер: 51
@philiphsinh9214
@philiphsinh9214 Жыл бұрын
This is easier to absorb than the official Android documentation. You rock!
@manishpingale6558
@manishpingale6558 3 жыл бұрын
I genuinely think that you explain very very easily ,I watched your some videos from newbie to pro series and they were AWESOME like I was having problem in KOTLIN LAMBDA FUNCTION but I understood after watching it THANK YOUUUUUU
@RodrigoGTomaz
@RodrigoGTomaz 3 жыл бұрын
Hi Philipp, Thank you for your very helpful videos! As far as your problem with the Viewpager overlapping the TabLayout when using ConstraintLayout, that can be fixed by setting the layout_heigh of the Viewpager to 0dp instead of match_parent.
@PhilippLackner
@PhilippLackner 3 жыл бұрын
Thanks for the info!
@d2words
@d2words 4 жыл бұрын
Very useful tutorial, I wonder what should we do if we want to replace a fragment on the fly?
@sonar_devices
@sonar_devices 3 жыл бұрын
Thank you so much!!
@guy1407
@guy1407 4 жыл бұрын
Thanks for the demo. I am not sure I would show this demo with tabs (not very useful), maybe another sample , tabs are used in many apps today
@chirantanchaudhury2809
@chirantanchaudhury2809 2 жыл бұрын
thank you very helpful
@gstarentertainmentedits2415
@gstarentertainmentedits2415 Жыл бұрын
Thanks bro 👌🙏
@Js-ig6jz
@Js-ig6jz 4 жыл бұрын
Hello, your videos are quite good. I have a question about how I can customize a CalendarView so I can add events
@ricardoestrella95
@ricardoestrella95 3 жыл бұрын
Hi Philipp, awesome videos. How can I pass multiple linearLayourts to each page in the adapter?
@odayprogrammer
@odayprogrammer 4 жыл бұрын
thanks :)
@user-cv6ej2kq7p
@user-cv6ej2kq7p 4 жыл бұрын
Thanks , that's great
@PhilippLackner
@PhilippLackner 3 жыл бұрын
You're welcome!
@jayceeddeyro1406
@jayceeddeyro1406 4 жыл бұрын
I want to use fragments with different layout for each tab? do you have a tutorial for that?
@hellosagar
@hellosagar 3 жыл бұрын
use tab layout with fragment
@daiyrkanybekov8575
@daiyrkanybekov8575 3 жыл бұрын
You are amazing broo
@PhilippLackner
@PhilippLackner 3 жыл бұрын
Thanks you too :)
@mehulbisht9708
@mehulbisht9708 4 жыл бұрын
if there are fragments that are hosted by the viewpager and you are getting data in those fragments from firebase then the first ( or default ) fragment of the layout has a bug that doesn't show the data because data wasn't loaded when the fragment was added to the viewpager. However the fragments after the first work as expected. What could be this bug ? For sure i know that data retrieved isn't null since i tried to add the same data to second fragment and it worked . it's just the timing .
@codeexplorer4212
@codeexplorer4212 3 жыл бұрын
Nice video. But whenever I am trying to browse any gallery of images horizontally in webview, the viewpager is landing on another view. Any suggestions?
@TheImaginativeSachin
@TheImaginativeSachin Жыл бұрын
can we apply this behaviour of tabs and view pagers to like bottom nav buttons and fragments. With like the attach( ) ?
@AlgeriaHere
@AlgeriaHere 4 жыл бұрын
very helpful video thank you , but just one question in the viewpageradapter , should we extend it from FragmenntStateAdapter and if yes please what did you pass as an argument for the constructor cause i m looking up for solution , didnt find any , thank you
@PhilippLackner
@PhilippLackner 4 жыл бұрын
Thanks! The viewpager2 uses a normal recyclerview adapter. If you use viewpager1 then you can use the FragmentStateAdapter
@AlgeriaHere
@AlgeriaHere 4 жыл бұрын
in my case i'm using viewpager2 , so i need to make a class that recyclerview adapter, and another little question if you dont mind , i m usin third party library called smarttablayout , is there way to pass that in tablayoutmediator because apparently it only takes the normal tablayout thank you
@PhilippLackner
@PhilippLackner 4 жыл бұрын
So I don't know that library, but if that custom tablayout is a subclass of tablayout then it should actually work to pass it to the mediator
@AlgeriaHere
@AlgeriaHere 4 жыл бұрын
it is actually a library and when i passed it , it said require tablayout , and mine is smarttablayout
@PhilippLackner
@PhilippLackner 4 жыл бұрын
Then it might be an older library that doesn't work with the new viewpager2. Then you need to use it with viewpager1 and create a fragmentstateadapter
@mohammadjeeshan4286
@mohammadjeeshan4286 4 жыл бұрын
Can you explain what is the difference between tabhost and tab layout in Android
@nonelelacele9300
@nonelelacele9300 Жыл бұрын
I've implemented something similar to this, but I have Icons on the tab Items. The tabs are always behind the app bar
@dharamveergupta3571
@dharamveergupta3571 3 жыл бұрын
How to make selected color for both text and icon of tab, other which aren't selected as greyed
@valarmorghulisx
@valarmorghulisx 4 жыл бұрын
Thank you so much! i tried it. but i have little problem. when i try to show toast message which are mixing. android studio is showing in same time. how can i solve it?
@PhilippLackner
@PhilippLackner 4 жыл бұрын
You mean you want to show two toasts one after another?
@valarmorghulisx
@valarmorghulisx 4 жыл бұрын
@@PhilippLackner No No, i just tried your code same. But when i clicked one tab after the another tab. it tried to show multi toast in same time. for example it shows "Unselected tab2" and "Selected tab1" so they are mixing.
@PhilippLackner
@PhilippLackner 4 жыл бұрын
@@valarmorghulisx yes that can happen when you show them at the same time. In production you should of course avoid this, I just wanted to show how the different events work here 👍
@valarmorghulisx
@valarmorghulisx 4 жыл бұрын
@@PhilippLackner ohh thank you so much :)
@alicenyw1872
@alicenyw1872 Жыл бұрын
For those who have TabLayoutMediator properties in red, it's because it wants you to use binding. Philipp shows how to set it up in one of his videos. Depending on what Id's you gave, your code should look something like this: TabLayoutMediator(binding.tabLayout, binding.viewPager,) { tab, position -> tab.text = "Tab ${position + 1}" }.attach()
@rotimidokun
@rotimidokun Жыл бұрын
Thanks Alice. This was helpful
@masoudkhedernezhad2810
@masoudkhedernezhad2810 2 жыл бұрын
in API 31 i cant do it... in this code TabLayoutMediator(tabLayout , ViewPager) {tab , position -> tab.text = "Tab ${position + 1}" }.attach() tabLayout in () get red and android studio says that i have to create a fun... help me pls
@nevresam.826
@nevresam.826 2 жыл бұрын
I have the same problem ... please help, how can we solve this?
@rowenarrow
@rowenarrow 2 жыл бұрын
Make sure you are using in activity_main.xml
@sujalaggrawal5481
@sujalaggrawal5481 9 ай бұрын
Try This instead! val adapter = ViewPagerAdapter(images) findViewById(R.id.viewPager).adapter = adapter TabLayoutMediator(findViewById(R.id.tabLayout),findViewById(R.id.viewPager)){ tab , position -> tab.text = "Tab ${position+1}" }.attach()
@flutteruz
@flutteruz 2 жыл бұрын
Yoooshlar🤣🤣
@chandrasaimohanbhupathi7837
@chandrasaimohanbhupathi7837 3 жыл бұрын
Hi Philip ! I am using a TabLayout that displays 3 Tabs. When the app is launched First Tab makes Webservice API call,I am not able to move to second tab until first tab First screen finishes Webservice call execution. Is there a way I can stop my First Tab execution when clicked on 2ndTab .
@mikec4220
@mikec4220 3 жыл бұрын
Are you doing the API call on a different thread?
@chandrasaimohanbhupathi7837
@chandrasaimohanbhupathi7837 3 жыл бұрын
Hi @@mikec4220 ! Thanks for replying. The webservice call is made on backgorund thread only. I found that, I am receiving 1000 records from Webservice which I need to populate recyclerview. No paging mechanism implemented from backend. The screen is getting stuck when applying all data to adapter. What I tried is I initialized adapter with empty data before making Webservice call. After receiving data from Webservice , I just updated data to a method in Adapter and called notifyDataSetChanged(). It looked ok as of now but still screen stucks a bit. Any idea on how to handle this kind of stituation from Mobile side if backend does not have paging mechanism.
@mikec4220
@mikec4220 3 жыл бұрын
Hi @@chandrasaimohanbhupathi7837 , I'm learning the ropes myself and by the look of it you are getting this behaviour because you're loading too much data. I believe the pagination was developed to solve this particular issue you are encountering. Also notifyDataSetChanged() is not the best to use with recyclerviews, not in this case at least, my understanding is that it will refresh all the views instead of only the ones needed. Look at diffutils, Phillip has a good example when he is setting up RecyclerView for the NewsApp. Hope this helps!
@Marinakulichok
@Marinakulichok 3 жыл бұрын
implementation 'com.google.android.material:material:1.3.0-alpha02'
@alfian3570
@alfian3570 3 жыл бұрын
Please add caption english
@chitgoks
@chitgoks 2 жыл бұрын
ViewPager2 is bad. The animation is too slow. When you have menu items, moving from tab 1 to 7, they will only change once animation ends. Dunno why they dont want to fix this.
SLIDABLE MENU WITH NAVIGATION DRAWER - Android Fundamentals
15:00
Philipp Lackner
Рет қаралды 94 М.
Smart Sigma Kid #funny #sigma #comedy
00:19
CRAZY GREAPA
Рет қаралды 24 МЛН
Please be kind🙏
00:34
ISSEI / いっせい
Рет қаралды 182 МЛН
She ruined my dominos! 😭 Cool train tool helps me #gadget
00:40
Go Gizmo!
Рет қаралды 60 МЛН
RECYCLERVIEW - Android Fundamentals
24:58
Philipp Lackner
Рет қаралды 101 М.
TabLayout в Android #1  | Kotlin + Android Studio
22:29
Neco Ru
Рет қаралды 10 М.
LAYOUT BASICS AND LINEAR LAYOUT - Android Fundamentals
16:45
Philipp Lackner
Рет қаралды 112 М.
TOASTS AND CONTEXT - Android Fundamentals
16:51
Philipp Lackner
Рет қаралды 36 М.
FRAGMENTS - Android Fundamentals
17:29
Philipp Lackner
Рет қаралды 323 М.
TEXTVIEWS - Android Fundamentals
14:09
Philipp Lackner
Рет қаралды 26 М.
Swipeable Tab Rows - UX With Material3
14:38
Philipp Lackner
Рет қаралды 23 М.
BROADCAST RECEIVERS - Android Fundamentals
8:01
Philipp Lackner
Рет қаралды 43 М.
🐞 Create a Android Tabbed Activity with new ViewPager2 and Fragments
16:32
CodeDocu Developer C# Asp Net Angular
Рет қаралды 13 М.
Smart Sigma Kid #funny #sigma #comedy
00:19
CRAZY GREAPA
Рет қаралды 24 МЛН