-
Notifications
You must be signed in to change notification settings - Fork 0
ViewBinding
findViewById()
has always worked well for me, but the documentation for ViewBinding highlights two areas of improvement, namely null safety and type safety. In my opinion, the former is not that big of a deal as it can be alleviated by more careful programming, whilst the latter can be caught during compilation.
Nonetheless, I decided to gave it a try and I found out that the code actually looked uglier than before, e.g.:
mBinding.characterSelectionLayoutNavBarWrapper.characterSelectionLayoutGameSwitcherButton.setText(getString(R.string.game_switcher_button_secrethitler));
mBinding.characterSelectionLayoutNavBarWrapper.characterSelectionLayoutGameSwitcherButton.addOnClickObserver(this::navigateToSecretHitlerCharacterSelectionFragment);
where previously, mBinding.characterSelectionLayoutNavBarWrapper.characterSelectionLayoutGameSwitcherButton
was just gameSwitcherButton
. The additional .characterSelectionLayoutNavBarWrapper
exists due to the use of <include />
tags in the XML layout files.
Hence, in my opinion, any migration to ViewBinding should be low-priority. As mentioned at the start, findViewById()
has always worked well for me, and there's really little value in fixing something that ain't broke.