https://kotlinlang.org logo
Title
a

Andy Gibel

04/01/2020, 1:52 PM
Does anyone else have near constant problems with Viewbinding/navigation components and Android Studio not recognizing the generated Kotlin code?
c

Colton Idle

04/01/2020, 2:37 PM
I've had some problems seemingly after adding viewBinding, but typically a clean would do the trick. Also assuming you used
<FragmentContainerView
as the host?
a

Andy Gibel

04/01/2020, 2:40 PM
ahh is that related? I was just using Fragment
which did work but gave me compiler warnings
c

Colton Idle

04/01/2020, 2:40 PM
Oooh! According to Ian you have to use FragmentContainerView
Because <fragment isn't really a view and so it messes a bunch of things up.
a

Andy Gibel

04/01/2020, 2:41 PM
lol OK. /shrug Android amirite?
thanks!
c

Colton Idle

04/01/2020, 2:41 PM
I recently enabled VB because FCV is now finally a thing.
I tried VB when it was brand new and it just wouldn't work with
<fragment
a

Andy Gibel

04/01/2020, 2:42 PM
ah ok. I was blaming that on the gradle plugin
c

Colton Idle

04/01/2020, 2:42 PM
Once I moved over to FragmentContainerView the only issue that was kind of a bummer was https://issuetracker.google.com/issues/142847973… but thankfully it's starting to appear towards the top of google searches.
a

Andy Gibel

04/01/2020, 2:42 PM
but yeah even in 3.6.2 was seeing issues with <fragment>
c

Colton Idle

04/01/2020, 2:43 PM
Hm. @Ian Lake ^? The issuetracker is showing private?
Anyway, the issue I was getting was at runtime, it didn't like that in my activity I think I was calling getNavController or one of those convenience methods, and it didn't work. If you search for that runtime crash, you should get an SO link to point you in the right direction. But yeah, that was my only real issue with getting VB started. That... and I had a couple of include and merge tag issues that weren't exactly clear, but now that I have VB. It's amazing.
Also, you probably saw it, but doing the whole VB dance in a fragment kinda sucks. Its ugly. @evant got a nice shoutout in this issue I filed https://issuetracker.google.com/issues/152333892
using a delegate makes it quite nice at the call-site
c

Colton Idle

04/01/2020, 2:49 PM
I did see like 5 different solutions so far. I also saw one interesting one that jw seemed to like where you use the views tag. But I do like evans article. I think trying to limit view interactions to onCreateView and not holding onto the field is where I'd ultimately love to go.
i

Ian Lake

04/01/2020, 3:17 PM
FWIW, it is the ... that is throwing off your link to the issue, it works when you go to https://issuetracker.google.com/issues/142847973
c

Colton Idle

04/01/2020, 4:42 PM
Thanks Ian. That's what I get for copy pasting from twitter.