Creating a Tab Layout with Icons & Fragments in Android Studio Tutorial (Kotlin)

  Рет қаралды 41,376

Indently

Indently

4 жыл бұрын

Hey guys! Make sure you don't pick all the same colours like I did in the video, it looks much better if you have 3 seperate colours for this. Other than that you can find the dependency down below:
Material Dependency: implementation 'com.google.android.material:material:1.1.0'

Пікірлер: 103
@DarkClosetOfTheMind
@DarkClosetOfTheMind 3 жыл бұрын
It's amazing how difficult they made it to create a simple tab control. 20 years ago with Visual Basic, it could have been done in under 5 mins. Thanks for the demonstration, it was helpful.
@jasongarey4093
@jasongarey4093 2 жыл бұрын
My thoughts exactly!
@ricardoestrella95
@ricardoestrella95 3 жыл бұрын
THIS is what I was looking for. Thank you so much for the explanation. By the way, if anyone followed the video exactly as it is, and android studio throws a Runtime error (I'm using android studio 4.1.1), delete the android:theme line in your activity_main.xml (line 21 in the video) or write it down just the in both day and night themes.xml
@lewishousden
@lewishousden 3 жыл бұрын
Thank you! Everyone overcomplicates things. this is simple and easy to follow.
@harshid4661
@harshid4661 3 жыл бұрын
there are thousands of videos only in java and not in kotlin. you are the one. thank you very much
@Roosevelth
@Roosevelth 4 жыл бұрын
every time you upload a video I learn a lot..thanks for that.
@LuisMartinez-ku6is
@LuisMartinez-ku6is 3 жыл бұрын
if you want to make this in a Fragment instead an activity, make exactly the same as the tutorial, the only modifications are: 1.- instead of write the code in the "MainActivity" use your "MainFragment" 2.- the whole code placed in "onCreate" you must to write it in "onActivityCreated" 3.- instead of "val adapter = ViewPagerAdapter(supportFragmentManager)" write "val adapter = ViewPagerAdapter(childFragmentManager) PD: i'm new usign android studio, i don't know if this is the best way to do this, but it worked for me, i hope i can help someone else!
@thekralj9600
@thekralj9600 3 жыл бұрын
i love you🥺 hahahaha i was losing my head for over 10 minutes and then i found this, thank you💪💪
@marc988
@marc988 2 жыл бұрын
Still can't figure this out.... :(
@dummytest6366
@dummytest6366 Жыл бұрын
my app keep crashing ... still cant figure it out
@BoonAaron
@BoonAaron 3 жыл бұрын
Crisp and Concise Loved it !! Thnx mate
@Indently
@Indently 3 жыл бұрын
Very happy to hear it helped!
@D3r_3k_
@D3r_3k_ 4 жыл бұрын
Ooooohhhhh you are great, super great! thanks for the video! you're the best
@mrpanda902
@mrpanda902 3 жыл бұрын
The best android developer
@veshvesh2157
@veshvesh2157 3 жыл бұрын
good job thanks mate!
@prashantrohilla1723
@prashantrohilla1723 3 жыл бұрын
you are awesome man. awesome video
@customdevvv
@customdevvv 2 жыл бұрын
Thanks helped a lot!
@pranavjadhav6496
@pranavjadhav6496 3 жыл бұрын
thanks a lot man!
@abhilashrajagopal9455
@abhilashrajagopal9455 2 жыл бұрын
Thank you for a nice content.
@magicwind7984
@magicwind7984 4 жыл бұрын
Thank! The only thing that didn't work for me was: "val adapter = ViewPagerAdapter(supportFragmentManager)". It worked like this: "val adapter = ViewPagerAdapter(childFragmentManager)"
@Indently
@Indently 4 жыл бұрын
Glad you could make it work!
@Kenzy1987
@Kenzy1987 3 жыл бұрын
@Magic Wind your comment just saved me. THANKS!!
@Kenzy1987
@Kenzy1987 3 жыл бұрын
And thank you Code Palace!!
@prkofc
@prkofc 3 жыл бұрын
Thanks man!!
@nathantanania6194
@nathantanania6194 3 жыл бұрын
@Magic Wind please can you explain to me how you solved this problem ?
@carlosvasquez5770
@carlosvasquez5770 3 жыл бұрын
The inglish it's not my first language, sorry. Thanks for this tutorial, it's really very helpful !
@Kab5892
@Kab5892 Жыл бұрын
I have managed to get this to work so I thought I should mention how I did this. Firstly really great video. This is solution for viewPager error around 10 mins into video. Similar to adding implementation you need to add the following in same build.gradle, this is all for kotlin , viewBinding { enabled = true } then make sure you sync, then in Mainactivity.kt private lateinit var binding: ActivityMainBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMainBinding.inflate(layoutInflater) setContentView(binding.root) setUpTabs() } private fun setUpTabs(){ val adapter = ViewPagerAdapter(supportFragmentManager) adapter.addFragment(HomeFragment(), "Home") adapter.addFragment(FavouritesFragment(), "Favourites") adapter.addFragment(SettingsFragment(), "Settings") binding.viewPager?.adapter = adapter binding.tabs?.setupWithViewPager(binding.viewPager)
@bzgede3533
@bzgede3533 3 жыл бұрын
Hello ;.. how can i open it. New fragment in the same area without leaving the tablayout when the button on the fragment is clicked.?
@zokirjonashiraliyev3299
@zokirjonashiraliyev3299 3 жыл бұрын
Thanks you for video.
@Effectivebasketball
@Effectivebasketball 3 жыл бұрын
One thing I do not understand to do all of it for adding 3 essentially buttons... that could be added in no time styled anyway I like as a vector and the rest the same as any other element. What is the point?
3 жыл бұрын
thank you very much
@mustafo6812
@mustafo6812 2 жыл бұрын
Thank you bro!!!
@brandanjong3092
@brandanjong3092 4 жыл бұрын
Nice vid, is this applicable to a fragment in an app that has bottom navigation already
@Kab5892
@Kab5892 Жыл бұрын
will still work as I have done it with bottom navigation already
@FaridCenreng-
@FaridCenreng- 2 жыл бұрын
i get this error, "Classifier 'HomeFragment' does not have a companion object, and thus must be initialized here" is it really okay to just delete companion object in fragment?
@sat_talk
@sat_talk 3 жыл бұрын
Thanks.. keep it up
@findsarfaraz
@findsarfaraz Жыл бұрын
R.drawable is already present in android studio use your custom Icons.
@marc988
@marc988 2 жыл бұрын
Mine doesn't accept neither "ViewPagerAdapter" , nor "SupportFragmentManager". How can I do it with sectionsPagerAdapter and supportFragmentManager ?
@stephanekamga24
@stephanekamga24 Жыл бұрын
thanks 👍
@muhammdshah9542
@muhammdshah9542 2 жыл бұрын
thank you
@user-ur7rt7go3z
@user-ur7rt7go3z 4 жыл бұрын
Спасибо!!!))
@yogeshgupta3809
@yogeshgupta3809 3 жыл бұрын
In 10:53 , viewPager is not recognized. So I try to use findViewById() method , but now it is giving error: Caused by: java.lang.NullPointerException: findViewById(R.id.viewPager) must not be null help me ;-(
@Indently
@Indently 3 жыл бұрын
Put into Google: Caused by: java.lang.NullPointerException: findViewById(R.id.viewPager) must not be null
@mergenc2522
@mergenc2522 2 жыл бұрын
just add the plugin in your app gradle: id 'kotlin-android-extensions'
@m4173_
@m4173_ 2 жыл бұрын
@@mergenc2522 omg, yes, this was actually the solution I was looking for for an hour now! Thank you very much!
@thomasmarchiotti5781
@thomasmarchiotti5781 3 жыл бұрын
Which type of project you choose when create? Empty activity??
@Indently
@Indently 3 жыл бұрын
empty activity
@AdrianGomez-gn7ig
@AdrianGomez-gn7ig 3 жыл бұрын
i got "Classifier 'HomeFragment' does not have a companion object, and thus must be initialized here" (missing "()", my bad )
@Indently
@Indently 3 жыл бұрын
We live and learn, good job on spotting it
@acunningclown
@acunningclown 2 жыл бұрын
at 10:53 when writing viewPager, my android studio does not link to the ViewPager (with id viewPager) in activity_main.xml. Does anyone have any ideas what I've done wrong?
@acunningclown
@acunningclown 2 жыл бұрын
it also does not reference 'tabs', have I failed to link them?
@Indently
@Indently 2 жыл бұрын
Hello Edward, unfortunately things get deprecated very fast in the world of Android. So what you're dealing with is that they deprecated what used to be known as "Kotlin synthetics", you need to explicity reference your views in your projects now.
@acunningclown
@acunningclown 2 жыл бұрын
@@Indently Hey, I think i solved the linking problem with binding, but now when i run the app in the emulator it doesn't display the tabs i made, just two default tabs. Any ideas? cheers Ed
@prashantsah5901
@prashantsah5901 2 жыл бұрын
@Edward were you able to resolve the issue? I am having the same linking problem.
@acunningclown
@acunningclown 2 жыл бұрын
@@prashantsah5901 I basically stopped using tabs and used a different base layout instead because it was more intuitive
@andrewbelozertsev6911
@andrewbelozertsev6911 2 жыл бұрын
Everything did like in a video. IDE dont show any problems. But app is crashes when started without any error. What i've done wrong?
@Indently
@Indently 2 жыл бұрын
I can't answer that unfortunately since it's too personal, I recommend searching on Google.
@sbartfe
@sbartfe 3 жыл бұрын
Is there any reason why you wouldn't use a constraint layout?
@Kab5892
@Kab5892 Жыл бұрын
No, can work in constraint as I have mine working, just make sure your constraint the item to top, bottom etc
@layly7961
@layly7961 3 жыл бұрын
Hello guys why my tab title didn't show in my tablayout?
@nevillevalentine4819
@nevillevalentine4819 Жыл бұрын
Hey ...when I type in the viewpager I'd on the mainActivity part it doesn't recognize it from the xml😢
@erzafixed5372
@erzafixed5372 Жыл бұрын
same , did u find a solution ,?
@Kab5892
@Kab5892 Жыл бұрын
@@erzafixed5372 I have managed to get this to work so I thought I should mention how I did this. Firstly really great video. This is solution for viewPager error around 10 mins into video. Similar to adding implementation you need to add the following in same build.gradle, this is all for kotlin , viewBinding { enabled = true } then make sure you sync, then in Mainactivity.kt private lateinit var binding: ActivityMainBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMainBinding.inflate(layoutInflater) setContentView(binding.root) setUpTabs() } private fun setUpTabs(){ val adapter = ViewPagerAdapter(supportFragmentManager) adapter.addFragment(HomeFragment(), "Home") adapter.addFragment(FavouritesFragment(), "Favourites") adapter.addFragment(SettingsFragment(), "Settings") binding.viewPager?.adapter = adapter binding.tabs?.setupWithViewPager(binding.viewPager)
@selcukkahrimanovic8701
@selcukkahrimanovic8701 4 жыл бұрын
Hi, thnx for this video but I'm taking this error. May u help me? Type mismatch. Required: (RecyclerView.Adapter?..RecyclerView.Adapter?) Found: HomePagerAdapter
@RaToCa99
@RaToCa99 3 жыл бұрын
I know what happened, you are using viewpage2 instead of viewpage
@meghagupta6359
@meghagupta6359 3 жыл бұрын
The title is not visible in my fragments. Can you please help?
@customdevvv
@customdevvv 2 жыл бұрын
did you change the color of the title?
@Surya-iu5cu
@Surya-iu5cu 2 жыл бұрын
icons are not showing in mine? anyone plz help
@bachtiarfariz24
@bachtiarfariz24 3 жыл бұрын
hi i really needs help, my code didnt recognized the viewPager id. what should i do?
@Spezialagent3000
@Spezialagent3000 2 жыл бұрын
i have the same issues, could someone help?
@MrStevemckie
@MrStevemckie Жыл бұрын
@@Spezialagent3000 add - id 'kotlin-android-extensions' - to you gradle plugins
@dadhaniaakhil9717
@dadhaniaakhil9717 3 жыл бұрын
Great, but how to highlight current fragment??
@Indently
@Indently 3 жыл бұрын
idk ask google
@technonews9
@technonews9 3 жыл бұрын
How to add recycle view in each of fragment ?! Please 🙏 answer 🙄
@Indently
@Indently 3 жыл бұрын
letmegooglethat.com/?q=how+to+add+a+recycler+view+to+a+fragment
@AdrianGomez-gn7ig
@AdrianGomez-gn7ig 3 жыл бұрын
Hello, did you manage to do this? im having trouble too. getting " java.lang.IllegalStateException: findViewById(R.id.recycler_capture)" on the activitys of the fragments, i did a include on the fragments, thats where "recycler_capture" is located but im gettings this error
@youssh4975
@youssh4975 3 жыл бұрын
it is ridiculous how overcomplicated android development is, i mean jesus, in web development with html css and js it takes like 10 minutes, and it actually is intuitive
@Indently
@Indently 3 жыл бұрын
I completely agree. I haven't tried out Compose yet, but I heard that it's intuitive as Web Dev
@youssh4975
@youssh4975 3 жыл бұрын
@@Indently also btw, thank you. Your video was really helpful.
@brserralheiro
@brserralheiro 3 жыл бұрын
I was enjoying until Kotlin came up. My query was android java, so I am not sure why I landed here. Maybe Java was used as a keyword, so I cannot say I like that. Why Kotlin? What is the benefit anyway?
@Indently
@Indently 3 жыл бұрын
The main reason is that Google chose Kotlin over Java, and that it's 10x faster to write the same code in Kotlin rather than in Java. I recommend you check it out since it's essentially the same language.
@brserralheiro
@brserralheiro 3 жыл бұрын
@@Indently Thanks for the reply. I always thought the main reason why they created Kotlin in first place was to be able to control Java. As a subset, one is able to make as many improvements to the syntax, and other aspects of the subset as necessary, like making coding faster, without being sued, like Microsoft was sued by Sun. As for being faster in performance, one would argue if any subset of Java can be faster than the actual Language it is going to be traslated to by the bytecode interpreter of the JVM. Java buildtime has at least one less hop and initial compilation is always faster. Maybe in the overall productive time of an Android developer it is worth it. Now, try going to the heavy duty world of Banking, and anything related to Finance, where Java code has been migrating COBOL/CICS platform and imprint that Kotlin is the future. Not even all developers from India would have the momentum to do that. So, for fun stuff, like Android, maybe it is a trend, for those newjoiners of programming (sorry, I meant coding, but I could not help it) who are starting now and never learned Java before, or for newjoiners of a project that is made in Kotlin because the architect is young. It is a natural tendency to try to simplify writing a piece of code. That is when Java came along in first place. C++ was just a bit too unecessarily low level for home appliances, and later for Finance. But then a Language takes a compiler, in the case of Java a JVM which is a compiler and an interpreter in a virtual machine, making the application much more secure. Kotlin is just a subset, for starters. Go came along and thumbs up to Google for that , when Blockchain, search engines and other complex application demands emerged in the internet era. Again a low level Language was necessary, with new features, multi-threading (concurrent) like Java, but with C++ low level capabilities, and an improved sintax. Google called the creators of Unix to create Go. That was something. IMHO Kotlin is just sugar for those seeking less thinking, more speed. Soon enough Kotlin will be history, because every high level code wll be generated using AI, Machine learning, Deep Learning ( low level programming) There is also Python, but that is another story. That is when Android development will be automated, like JS, and other superficial UI stuff. Like Groove, Scala, and other ones not really worh mentioning here, Kotlin is a just moment. it is amusing to see the keyword fun, though. It makes it much more fun, doesn't it? [...]s.
@Indently
@Indently 3 жыл бұрын
I can't speak for any other kind of development, but for Android, Google chose to support it 100%. Does that make me a sheep to follow what Google promotes? Yes. But again, for android development, especially if you use android studio, I personally believe you'd be complicating your life for no reason if you continued using Java . And even if it is a movement, or if it decides to no longer be supported tomorrow, it was still worth learning while it existed (Kotlin should take you no longer than a couple of hours to learn if you are familiar with Java). The fact is, it made a lot of the code more readable and easier to code in android studio. I personally don't care if people decided to use Kotlin or not, that's their choice. I'm just using what Google and the Intelij team offered and recommended for creating apps. I can't provide you any further arguments, because I'm just sharing what I learned from my own experience. But I'm sure the Intelij team and Google Inc. have some documentation to further support their decision! But I'm also concentrating on Python, because I'm certain at a certain point that a lot of these programming languages will become most certainly redundant with machine learning (including even Python lol). But thanks for the comment! Whatever decision you take for development, I'm sure you'll make it work.
@javierllanos5532
@javierllanos5532 3 жыл бұрын
@@Indently Yo uso kotlin y es mejor que java.
@Karuni7
@Karuni7 4 жыл бұрын
Will like for coffee
@SvScibi
@SvScibi 3 жыл бұрын
I cant access viewpager and tabs from by main activity...can anyone help me
@eiorajlf
@eiorajlf 3 жыл бұрын
Same
@suppp24
@suppp24 3 жыл бұрын
@@eiorajlf same
@Kab5892
@Kab5892 Жыл бұрын
@@suppp24 I have managed to get this to work so I thought I should mention how I did this. Firstly really great video. This is solution for viewPager error around 10 mins into video. Similar to adding implementation you need to add the following in same build.gradle, this is all for kotlin , viewBinding { enabled = true } then make sure you sync, then in Mainactivity.kt private lateinit var binding: ActivityMainBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMainBinding.inflate(layoutInflater) setContentView(binding.root) setUpTabs() } private fun setUpTabs(){ val adapter = ViewPagerAdapter(supportFragmentManager) adapter.addFragment(HomeFragment(), "Home") adapter.addFragment(FavouritesFragment(), "Favourites") adapter.addFragment(SettingsFragment(), "Settings") binding.viewPager?.adapter = adapter binding.tabs?.setupWithViewPager(binding.viewPager)
@the_legend_of_xd
@the_legend_of_xd 3 жыл бұрын
In my code it cant find "viewPager". 10:52
@imaginefree9143
@imaginefree9143 3 жыл бұрын
did you fix it?
@the_legend_of_xd
@the_legend_of_xd 3 жыл бұрын
@@imaginefree9143 no
@Indently
@Indently 3 жыл бұрын
You need to try using findviewbyid or viewbinding , they deprecated Kotlin synthetics
@the_legend_of_xd
@the_legend_of_xd 3 жыл бұрын
@@Indently Thank you fot the fast response :) I'll try it tomorrow
@berryerpacic9995
@berryerpacic9995 3 жыл бұрын
@@Indently Interesting approach but didnt work 4 me.. i dont know what to do.. ty for your time tho.. ^.^
@tomasmenniti7406
@tomasmenniti7406 2 жыл бұрын
didn´t work >:(
@Indently
@Indently 2 жыл бұрын
Code Palace apologises for the inconveniences this video may have caused. Code Palace also recommends that the person watching this video learns the basics of Android before trying more complex tutorials such as this one. Code Palace wishes the user a pleasant journey and a pleasant day.
@theterminaltech3323
@theterminaltech3323 3 жыл бұрын
can you please give code?
@xXV1ralXx
@xXV1ralXx 3 жыл бұрын
Started off great but towards the adaptors absolutely got lost! Way too fast
@MartiinGBROTMG
@MartiinGBROTMG 2 жыл бұрын
I Don't know how to migrate from kotlin synthethics to te new Bindings form. all of this because at 10:53 when writing viewPager, my android studio does not link to the ViewPager TRASH OF VIDEO
@jabi2960
@jabi2960 Жыл бұрын
for the erro of not finding the viewPager.adapter = adapter its because you need binding to do so, just write binding.viewPager.adapter = adapter
20 Everyday Tips & Tricks in Python
25:18
Indently
Рет қаралды 10 М.
Smart Sigma Kid #funny #sigma #comedy
00:19
CRAZY GREAPA
Рет қаралды 24 МЛН
The day of the sea 🌊 🤣❤️ #demariki
00:22
Demariki
Рет қаралды 90 МЛН
5 Useful Python Decorators (ft. Carberra)
14:34
Indently
Рет қаралды 90 М.
CREATING SWIPABLE VIEWS WITH VIEWPAGER 2 - Android Fundamentals
11:56
Philipp Lackner
Рет қаралды 65 М.
SQLite Database for Android - Full Course
1:28:22
freeCodeCamp.org
Рет қаралды 245 М.
Custom TabLayout in Android
11:39
XamDroid
Рет қаралды 14 М.
How to Create Fragments in Android Studio (2023) | Fragment Activity
11:40
5 Really Cool Python Functions
19:58
Indently
Рет қаралды 54 М.