https://kotlinlang.org logo
#android
Title
# android
s

sindrenm

07/27/2018, 12:08 PM
I prefer 1️⃣ because it Just Works™ out of the box and is dead simple to use. However, it does “require” me to give the views IDs in camelCase in the layouts, which I am fine with personally, but I know many others don't like it. With snake_case IDs in layout files, I think I'd prefer 5️⃣, which is what we use at work. We defined a simple
find
extension on
View
that just encapsulates lazily finding the view through `lazy`:
Copy code
fun <T : View> View.find(id: Int) = lazy(LazyThreadSafetyMode.NONE) { findViewById<T>(id) }
Usage:
Copy code
<Button id="@+id/some_button" />
Copy code
class SomeView : View {
  private val someButton: Button by find(R.id.some_button)
}
r

rkeazor

07/27/2018, 1:42 PM
I think you can name things the way you want, with android extensions.
g

gildor

07/28/2018, 5:57 AM
It's actually the same what Kotterknife does, it's convenient but has a couple significant problems: Cannot be used in a fragment, or any other component which has view lifecycle inside, because you just cannot update view inside of delegate (you can add some handler for that, but imho it's very hacky Another problem is efficientcy, one more object per field
💯 2