androidnullnull-checkviewbinding

Do I have to null check every time before referencing an element in view binding?


So this isn't really a issue, I am just curious, do I really have to null check every time I use view binding? I find it a bit annoying having to put the question mark every time (binding?.[layout item]).

Can somebody please give me a solution to this if it's possible?


Solution

  • The only reason you would be doing this is if you had marked the Binding object as nullable, e.g. lateinit var binding MainActivityBinding?. Which there is no need for.