Skip to content

Instantly share code, notes, and snippets.

@sys1yagi
Created May 12, 2017
Embed
What would you like to do?
Magic Data Binding inflate
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val binding = parent.inflateBinding<ListItemCommentBinding>()
return ViewHolder(binding)
}
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