Kotlin Synthetic (Deprecated) - Migrate to View Binding | Android Studio Tutorial

Поділитися
Вставка
  • Опубліковано 28 січ 2025

КОМЕНТАРІ • 67

  • @sanankazimov
    @sanankazimov 9 місяців тому

    My Master!

  • @mariojosuecastro303
    @mariojosuecastro303 Рік тому

    Great Video! This solved the issue I had. Thank you @Stevdza-San

  • @codingwithphantom3607
    @codingwithphantom3607 4 роки тому +4

    You are perfect bro!!!
    please make a tutorial about Jetpack Compose

  • @coldwolf5050
    @coldwolf5050 4 роки тому +4

    Hi, any plans on doing jetpack compose?

  • @StevdzaSan
    @StevdzaSan  4 роки тому +1

    If you want a layout file to be ignored while generating binding classes, add the tools:viewBindingIgnore="true" attribute to the root view of that layout file.

    • @vishalgaurav4411
      @vishalgaurav4411 4 роки тому +2

      Why would I want to do that?

    • @orlando7968
      @orlando7968 4 роки тому +1

      @@vishalgaurav4411 I have the same question, wouldn't I just not wrap the view in a ?

  • @RealLeel
    @RealLeel Рік тому

    Great video! Thank you so much brother🤝🏾🤝🏾

  • @NishantKumar-cr6fb
    @NishantKumar-cr6fb 4 роки тому

    Hi ,
    Don't know how to contact you on udemy .
    At video 32 , 3:34
    3 and 4 methods have same name .. 4 should ld be areContents something

  • @sixtoolguin
    @sixtoolguin 4 роки тому

    if i have this sentence "val apellido = addApellido_et.text.toString()" how can i change in binding????

  • @rezakhalafi528
    @rezakhalafi528 9 місяців тому

    Amazing bro

  • @aryanvikash1967
    @aryanvikash1967 4 роки тому +11

    But why ? 😭

    • @StevdzaSan
      @StevdzaSan  4 роки тому +2

      - They pollute the global namespace
      - They don’t expose nullability information
      - They only work in Kotlin code

    • @h.r.60
      @h.r.60 4 роки тому

      i feel like google will eventually find a better solution or workaround though

    • @Tone463
      @Tone463 3 роки тому

      @@StevdzaSan dear, I respect you so much. Could you please explain where do you refer to when saying "they"? Thank you for your time! Your videos are very helpful.

    • @bagadeshkumarr9502
      @bagadeshkumarr9502 3 роки тому

      @@Tone463 He refers to Kotlin-Synthetics

    • @Tone463
      @Tone463 3 роки тому

      @@bagadeshkumarr9502 thanks friend! 👋🏽

  • @sdfewvdevvv
    @sdfewvdevvv 3 роки тому

    Hello. I have done exactly what you did but I encountered a problem when I migrate the Main Activity into View Binding. It did not generate ActivityMainBinding. What do you think is the reason? Thank you.

  • @rahmantech5340
    @rahmantech5340 3 роки тому

    Great explanation, thanks bro

  • @4ytonly
    @4ytonly 4 роки тому +1

    Why binding instead of findViewById? Is there any resource or speed gain or...?

    • @打直走的螃蟹
      @打直走的螃蟹 4 роки тому +1

      findViewById is more computation work needed

    • @Another0neTime
      @Another0neTime 4 роки тому +1

      It traverses the entire view hierarchy, where viewbinding does not.

  • @quicksketch1617
    @quicksketch1617 4 роки тому +1

    There is a diference if it's RecyclerView?

    • @StevdzaSan
      @StevdzaSan  4 роки тому

      Yes a slightly difference. I'll record a video about it as well (After my Hash Generator Series).

    • @quicksketch1617
      @quicksketch1617 4 роки тому

      @@StevdzaSan Thank you

  • @bayudwisaputra9
    @bayudwisaputra9 4 роки тому

    it's great bro, but, can you show how to roll back to the previous version on project structure?

  • @ChristopherNeurofunker
    @ChristopherNeurofunker 4 роки тому

    What is the Parcelize alternative?

    • @kenargo
      @kenargo 4 роки тому

      See: developer.android.com/kotlin/parcelize

  • @khumokwezimashapa2245
    @khumokwezimashapa2245 3 роки тому

    How do I start an activity from fab after using viewbinding?

  • @4ytonly
    @4ytonly 4 роки тому +1

    Hi, just transitioning from java, and... what is the java equivalent of val binding get() = _binding!! and also what is that !! at the end? :)

    • @StevdzaSan
      @StevdzaSan  4 роки тому +1

      We are basically getting the value of _binding and setting in on binding variable which is read only. And this "!!" is called double bang operator:
      stackoverflow.com/questions/34342413/what-is-the-kotlin-double-bang-operator

    • @4ytonly
      @4ytonly 4 роки тому

      @@StevdzaSan OK thx, but why not just val binding = _binding? Why get()?

    • @StevdzaSan
      @StevdzaSan  4 роки тому +2

      @4YT It's a getter which can omit the type automatically, plus it will be called every-time we access the property.

  • @idedhica
    @idedhica 4 роки тому

    when i add include layout it's not call when using view Binding .. how to solve that? thanks

    • @idedhica
      @idedhica 4 роки тому

      also how using view binding on bottom sheet dialog?

  • @AmirGibtEuch
    @AmirGibtEuch 4 роки тому

    Thank you very much bro!

  • @Effectivebasketball
    @Effectivebasketball 4 роки тому

    Hello, great video as always. ViewBinding amazing and working fine with Fragments, yet I had a hard time to use it when I walked with several activities that not part of the navigation, inactivity fine, but when I just to the next activity I personally had a hard time to initialize and even after it seems like all smooth and well it return null. in most cases. Is there a way to use viewBinding in a project with several activities? Another question might be i should not even bother with it? because fragments seem to be the future. Yet when I only need 2-3 pages it feels faster and easy to just use Inten instead of nav_... yea forgot view binding is auto-generated so it sure quicker :)

  • @techpal5525
    @techpal5525 4 роки тому

    does passing Data, works in View binding method ?

  • @johnkline4350
    @johnkline4350 3 роки тому +5

    This is stupid. When a piece of code is written, it should continue to function for at least a decade without having to make any modifications to it. Anything else is wrong. Period. Now I and tens of thousands of other devs have to go through hundreds of thousands of Activities and Fragments to "fix" formerly perfectly working code if we want our apps to ever compile again. Google's Android teams can go sodomize themselves with a broken DVD containing the Kotlin plugin, Java, 15 copies of Gradle, Android Studio, and adb, followed by some rusty nails, broken glass, a cactus, and two laptop batteries on fire. Oh and view binding isn't working for me 100% perfectly either. After several hours of wrestling with this utter nonsense, I still have a couple of references that aren't working at all despite everything set up in the XML layouts just like all of the other view references that ARE working fine. So they can put their super-special view binding trash onto its own separate broken DVD and shove the sharpest pieces they can find up their collective rears too. /endrant Okay. Now that THAT is out of my system. Back to work, I guess.

  • @ayushranjan3472
    @ayushranjan3472 3 роки тому

    followed your steps line by line but showing error,and asking to create class FragmentHomeBinding

    • @StevdzaSan
      @StevdzaSan  3 роки тому

      Rebuild the project if your Android Studio somehow does not recognize the class.

    • @ayushranjan3472
      @ayushranjan3472 3 роки тому

      @@StevdzaSan It was typo mistake, thank you very much for your reply

  • @abddulrahmanas
    @abddulrahmanas 4 роки тому

    Can I use findviewbyid instead of view binding? I mean is there any problems with that? and why I should migrate to view binding?
    Thanks for the tutorial.

    • @noahvo6673
      @noahvo6673 4 роки тому +1

      findviewbyid will do a search an entire list of id to find the view, that would reduce/lag the performance
      by the video, we should migrate because in the future, android doesn't support the method any more so it may cause error/crash

    • @abddulrahmanas
      @abddulrahmanas 4 роки тому

      @@noahvo6673
      Thank you!

    • @khumokwezimashapa2245
      @khumokwezimashapa2245 3 роки тому

      @@noahvo6673 So basically we have no choice

  • @carlosaguirre746
    @carlosaguirre746 3 роки тому

    Thanks a lot!!!!!

  • @muhammadshayankhan3066
    @muhammadshayankhan3066 4 роки тому

    What about databinding? Is it a better alternative ?

    • @StevdzaSan
      @StevdzaSan  4 роки тому +1

      View Binding and Data Binding are both fine.

    • @byronlovelace8379
      @byronlovelace8379 4 роки тому +1

      Until next year...

    • @kenargo
      @kenargo 4 роки тому

      dataBinding is way overkill and using it requires you to use binding for all view access, you would need to convert your onClickXX, onTouchXX, etc to all use dataBinding, you are blocked from using callbacks (yes, I found this out the hard way :( ) Sure, dataBinding would work, but only use it if you also expedct to use it for everything

  • @h.r.60
    @h.r.60 4 роки тому

    What's your favorite Android app you've made and why?

  • @عالمالبرمجةالعربي

    Thank you this video are very helpful but the problem is not solved

  • @M7MDfouad
    @M7MDfouad 3 роки тому

    thnx

  • @ilhamaliyudin4779
    @ilhamaliyudin4779 3 роки тому

    Wait @Parcelize too?? Oh noo.

    • @StevdzaSan
      @StevdzaSan  3 роки тому

      Just add this plugin and everything will be just fine: id 'kotlin-parcelize'

    • @ilhamaliyudin4779
      @ilhamaliyudin4779 3 роки тому

      @@StevdzaSan thank you master 🙏🙏🙏

  • @samstoyroom
    @samstoyroom 4 роки тому

    I would just use "dataBinding true", it includes View Binding.

    • @adipradhan3506
      @adipradhan3506 4 роки тому +3

      Using data binding for this is like using a sword for cutting potato

    • @kenargo
      @kenargo 4 роки тому

      dataBinding is way overkill and using it requires you to use binding for all view access, you would need to convert your onClickXX, onTouchXX, etc to all use dataBinding, you are blocked from using callbacks (yes, I found this out the hard way :( )

  • @thelight786
    @thelight786 Рік тому +1

    thanks, but if u have a hundred files to migrate then that's a huge effort

  • @MrRahulmalik
    @MrRahulmalik 4 роки тому +1

    How to use with custom alert dialogs and bottom sheet dialogs?
    I have 4 different layout files for dialogs and bottom sheets
    How to convert them into ViewBinding with activity and fragments?

  • @matthewbaynham6286
    @matthewbaynham6286 Рік тому

    And that is suppose to be easy, whoever in in charge of Android Studio is not very good at their job. Why on earth is this so complex, in other technologies you can use the name of the controls you add to the GUI.

  • @fyanahmad9418
    @fyanahmad9418 4 роки тому

    viewBinding is safe

  • @rizkiadisaputra5971
    @rizkiadisaputra5971 4 роки тому

    View binding alternative