View Binding in Android
View Binding is a functionality that you use to map the xml views with the kotlin (ot JAVA) file, so it can be used in the kotlin program. It is a great replacement of findViewById.
Initially, when kotlin was adapted as a new programming language for android development, it had a functionality called kotlin synthetics, which gave the programmer the ease of using xml view ids in to kotlin file directly by writing the id itself. As amazing as it sounds, it had a great loop hole which could lead to a null pointer exceptions many times when you do not get the id right. Hence, it is deprecated in recent times. So, the better way to map the views is to use View Binding instead of calling findViewById for every views we have in xml.
To use view binding, we first need to add a small piece of code in our gradle file of module level inside android block. The code can be seen in the below picture.
Once this code is entered in the gradle file, the project needs to be sync. After synchronization, it will then generate auto-generated files in our project, through which we can map our views with kotlin file.