Created
May 12, 2017 04:28
-
-
Save sys1yagi/d9c868f06b3e2f70cd725858131767d2 to your computer and use it in GitHub Desktop.
Magic Data Binding inflate
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
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { | |
val binding = parent.inflateBinding<ListItemCommentBinding>() | |
return ViewHolder(binding) | |
} |
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 T : ViewDataBinding> View.inflateBinding(): T { | |
return T::class.java | |
.getDeclaredMethod("inflate", LayoutInflater::class.java, ViewGroup::class.java, Boolean::class.javaPrimitiveType) | |
.invoke(null, LayoutInflater.from(context), this, false) as T | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment