I prefer :one: because it Just Works™ out of the b...
# android
s
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
I think you can name things the way you want, with android extensions.
g
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