https://youtu.be/QFzuE55s_Mc

ViewBinding is a feature in Android that allows developers to easily reference views in their code without the need for findViewById() method calls. There are two types of ViewBinding available in Android:

1. View Binding for Activities

View Binding for Activities is used to bind views in layouts that are set for Activities. To use View Binding in Activities, add the following lines of code to your app's build.gradle file:

android {
    ...
    buildFeatures {
        viewBinding true
    }
}

After adding this code, you can use View Binding in your Activities by creating a binding object using the following code:

private lateinit var binding: ActivityMainBinding

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    binding = ActivityMainBinding.inflate(layoutInflater)
    setContentView(binding.root)

		binding.textview_username.text = ""
		binding.button_login.text = ""
		binding.button_sign_up = text
}

2. View Binding for Fragments

View Binding for Fragments is used to bind views in layouts that are set for Fragments. To use View Binding in Fragments, add the following lines of code to your app's build.gradle file:

android {
    ...
    buildFeatures {
        viewBinding true
    }
}

After adding this code, you can use View Binding in your Fragments by creating a binding object using the following code:

private var _binding: FragmentMainBinding? = null
private val binding get() = _binding!!

override fun onCreateView(
    inflater: LayoutInflater,
    container: ViewGroup?,
    savedInstanceState: Bundle?
): View {
    _binding = FragmentMainBinding.inflate(inflater, container, false)
    return binding.root
}

override fun onDestroyView() {
    super.onDestroyView()
    _binding = null
}

These are the two types of ViewBinding available in Android. You can choose the one that suits your needs and start using it in your app development.