ViewBinding in Activity - Forget about findViewById | Android Studio Kotlin in just 3 minutes [2022]

60 Просмотры
Издатель
This video teaches you everything you need to know about ViewBinding in Android.
Finally, this is end of the findViewById in Android Studio. Now We'll use ViewBinding to work on XML Views. ViewBinding is much more easier and efficient as compare to findViewById.
.
ViewBinding Steps:
1. Enable View Binding in Build Gradle(project: app)
2. Use ViewBinding Class in Activity
3. Start using binding with XML Views

Disclaimer:

This video is for educational purpose only.
Copyright Disclaimer Under Section 107 of the Copyright Act 1976, allowance is made for "FAIR USE" for purposes such as criticism, comment, news reporting, teaching, scholarship, and research.
"FAIR USE" is a use permitted by Copyright Statute that might otherwise be infringing.
Non-profit, Educational or Personal use tips the balance in favor of Fair Use.

View binding is a feature that allows you to more easily write code that interacts with views. Once view binding is enabled in a module, it generates a binding class for each XML layout file present in that module. An instance of a binding class contains direct references to all views that have an ID in the corresponding layout. In most cases, view binding replaces findViewById.

View binding has important advantages over using findViewById:

* Null safety: Since view binding creates direct references to views, there's no risk of a null pointer exception due to an invalid view ID. Additionally, when a view is only present in some configurations of a layout, the field containing its reference in the binding class is marked with @Nullable.
* Type safety: The fields in each binding class have types matching the views they reference in the XML file. This means that there's no risk of a class cast exception.
Please Like share and subscribe....!!!!!
Thankyou
Категория
Язык программирования Kotlin
Комментариев нет.