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

แชร์
ฝัง
  • เผยแพร่เมื่อ 29 ส.ค. 2024
  • 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'

ความคิดเห็น • 104

  • @DarkClosetOfTheMind
    @DarkClosetOfTheMind 3 ปีที่แล้ว +36

    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.

  • @LuisMartinez-ku6is
    @LuisMartinez-ku6is 3 ปีที่แล้ว +19

    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 ปีที่แล้ว +2

      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

  • @harshid4661
    @harshid4661 3 ปีที่แล้ว +1

    there are thousands of videos only in java and not in kotlin. you are the one. thank you very much

  • @ricardoestrella95
    @ricardoestrella95 3 ปีที่แล้ว +1

    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 ปีที่แล้ว +2

    Thank you! Everyone overcomplicates things. this is simple and easy to follow.

  • @Roosevelth
    @Roosevelth 4 ปีที่แล้ว +3

    every time you upload a video I learn a lot..thanks for that.

  • @mrpanda902
    @mrpanda902 4 ปีที่แล้ว +2

    The best android developer

  • @magicwind7984
    @magicwind7984 4 ปีที่แล้ว +14

    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 ปีที่แล้ว +1

      Glad you could make it work!

    • @Kenzy1987
      @Kenzy1987 3 ปีที่แล้ว +1

      @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 ปีที่แล้ว +3

    The inglish it's not my first language, sorry.
    Thanks for this tutorial, it's really very helpful !

  • @Kab5892
    @Kab5892 ปีที่แล้ว +1

    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)

  • @BoonAaron
    @BoonAaron 4 ปีที่แล้ว +3

    Crisp and Concise
    Loved it !!
    Thnx mate

    • @Indently
      @Indently  4 ปีที่แล้ว

      Very happy to hear it helped!

  • @D3r_3k_
    @D3r_3k_ 4 ปีที่แล้ว +2

    Ooooohhhhh
    you are great, super great! thanks for the video! you're the best

  • @acunningclown
    @acunningclown 2 ปีที่แล้ว +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 ปีที่แล้ว +1

      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

  • @bzgede3533
    @bzgede3533 3 ปีที่แล้ว +1

    Hello ;..
    how can i open it. New fragment in the same area without leaving the tablayout when the button on the fragment is clicked.?

  • @yogeshgupta3809
    @yogeshgupta3809 3 ปีที่แล้ว +2

    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 3 ปีที่แล้ว +3

      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!

  • @nevillevalentine4819
    @nevillevalentine4819 2 ปีที่แล้ว +1

    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)

  • @brandanjong3092
    @brandanjong3092 4 ปีที่แล้ว +3

    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?

  • @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?

  • @findsarfaraz
    @findsarfaraz ปีที่แล้ว

    R.drawable is already present in android studio use your custom Icons.

  • @zokirjonashiraliyev3299
    @zokirjonashiraliyev3299 3 ปีที่แล้ว +2

    Thanks you for video.

  • @AdrianGomez-gn7ig
    @AdrianGomez-gn7ig 3 ปีที่แล้ว +1

    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

  • @marc988
    @marc988 2 ปีที่แล้ว

    Mine doesn't accept neither "ViewPagerAdapter" , nor "SupportFragmentManager". How can I do it with sectionsPagerAdapter and supportFragmentManager ?

  • @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.

  • @veshvesh2157
    @veshvesh2157 3 ปีที่แล้ว +1

    good job thanks mate!

  • @abhilashrajagopal9455
    @abhilashrajagopal9455 2 ปีที่แล้ว +1

    Thank you for a nice content.

  • @youssh4975
    @youssh4975 3 ปีที่แล้ว +2

    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 ปีที่แล้ว +1

      @@Indently also btw, thank you. Your video was really helpful.

  • @prashantrohilla1723
    @prashantrohilla1723 3 ปีที่แล้ว

    you are awesome man. awesome video

  • @pranavjadhav6496
    @pranavjadhav6496 4 ปีที่แล้ว +1

    thanks a lot man!

  • @technonews9
    @technonews9 3 ปีที่แล้ว +1

    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

  •  3 ปีที่แล้ว +1

    thank you very much

  • @brserralheiro
    @brserralheiro 4 ปีที่แล้ว +1

    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  4 ปีที่แล้ว +1

      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 4 ปีที่แล้ว +1

      @@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  4 ปีที่แล้ว

      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.

  • @customdevvv
    @customdevvv 3 ปีที่แล้ว

    Thanks helped a lot!

  • @the_legend_of_xd
    @the_legend_of_xd 3 ปีที่แล้ว +1

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

  • @muhammdshah9542
    @muhammdshah9542 2 ปีที่แล้ว

    thank you

  • @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

    • @iiiFiinka
      @iiiFiinka หลายเดือนก่อน

      val viewPager = findViewById(R.id.viewPager)
      viewPager.adapter = adapter

  • @layly7961
    @layly7961 3 ปีที่แล้ว

    Hello guys why my tab title didn't show in my tablayout?

  • @thomasmarchiotti5781
    @thomasmarchiotti5781 3 ปีที่แล้ว

    Which type of project you choose when create? Empty activity??

    • @Indently
      @Indently  3 ปีที่แล้ว

      empty activity

  • @stephanekamga24
    @stephanekamga24 ปีที่แล้ว

    thanks 👍

  • @Surya-iu5cu
    @Surya-iu5cu 3 ปีที่แล้ว

    icons are not showing in mine? anyone plz help

  • @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 ปีที่แล้ว +1

      I know what happened, you are using viewpage2 instead of viewpage

  • @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?

    • @Smokie56
      @Smokie56 2 ปีที่แล้ว +1

      @@Spezialagent3000 add - id 'kotlin-android-extensions' - to you gradle plugins

  • @mustafo6812
    @mustafo6812 2 ปีที่แล้ว

    Thank you bro!!!

  • @meghagupta6359
    @meghagupta6359 3 ปีที่แล้ว

    The title is not visible in my fragments. Can you please help?

    • @customdevvv
      @customdevvv 3 ปีที่แล้ว

      did you change the color of the title?

  • @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

  • @sat_talk
    @sat_talk 3 ปีที่แล้ว

    Thanks.. keep it up

  • @dadhaniaakhil9717
    @dadhaniaakhil9717 3 ปีที่แล้ว

    Great, but how to highlight current fragment??

    • @Indently
      @Indently  3 ปีที่แล้ว

      idk ask google

  • @user-ur7rt7go3z
    @user-ur7rt7go3z 4 ปีที่แล้ว +1

    Спасибо!!!))

  • @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)

  • @MartiinGBROTMG
    @MartiinGBROTMG 2 ปีที่แล้ว +1

    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

  • @Karuni7
    @Karuni7 4 ปีที่แล้ว +1

    Will like for coffee

  • @tomas.menniti
    @tomas.menniti 2 ปีที่แล้ว

    didn´t work >:(

    • @Indently
      @Indently  2 ปีที่แล้ว +1

      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.

  • @xXV1ralXx
    @xXV1ralXx 4 ปีที่แล้ว

    Started off great but towards the adaptors absolutely got lost! Way too fast

  • @theterminaltech3323
    @theterminaltech3323 3 ปีที่แล้ว

    can you please give code?