-
-
Save CodingDoug/43d17d44459805e51072 to your computer and use it in GitHub Desktop.
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
//inline fun <reified TV : View> v(context: Context, init: TV.() -> Unit) : TV { | |
inline fun <reified TV : View> Context.v(init: TV.() -> Unit) : TV { | |
val constr = TV::class.java.getConstructor(Context::class.java) | |
// val view = constr.newInstance(context) | |
val view = constr.newInstance(this) | |
view.init() | |
return view | |
} | |
//inline fun <reified TV : View> v(parent: ViewGroup, init: TV.() -> Unit) : TV { | |
inline fun <reified TV : View> ViewGroup.v(init: TV.() -> Unit) : TV { | |
val constr = TV::class.java.getConstructor(Context::class.java) | |
// val view = constr.newInstance(parent.context) | |
val view = constr.newInstance(context) | |
parent.addView(view) | |
view.init() | |
return view | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment