Last active
February 4, 2020 08:00
-
-
Save lordcodes/1aa90e8a1815e0ac53ed3b75032155f2 to your computer and use it in GitHub Desktop.
Code for article "Using Kotlin to bind Android views"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun <ViewT : View> Activity.bindView(@IdRes idRes: Int): Lazy<ViewT> { | |
return lazyUnsychronized { | |
findViewById<ViewT>(idRes) | |
} | |
} | |
class PlanningActivity : AppCompatActivity() { | |
private val planningText by bindView<TextView>(R.id.planning_text) | |
// or | |
private val planningText: TextView by bindView(R.id.planning_text) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment