Skip to content

Instantly share code, notes, and snippets.

@sys1yagi
Created May 12, 2017 04:28
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sys1yagi/d9c868f06b3e2f70cd725858131767d2 to your computer and use it in GitHub Desktop.
Save sys1yagi/d9c868f06b3e2f70cd725858131767d2 to your computer and use it in GitHub Desktop.
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