Skip to content

Instantly share code, notes, and snippets.

@Temidtech
Created April 23, 2018 13:51
Show Gist options
  • Save Temidtech/e7b6b234d7e90bb8aa8a0f412cd25756 to your computer and use it in GitHub Desktop.
Save Temidtech/e7b6b234d7e90bb8aa8a0f412cd25756 to your computer and use it in GitHub Desktop.
// Extend ViewGroup class with inflate function
fun ViewGroup.inflate(layoutRes: Int): View {
return LayoutInflater.from(context).inflate(layoutRes, this, false)
}
==================================
// Call inflate directly on the ViewGroup instance
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val v = parent.inflate(R.layout.view_item)
return ViewHolder(v)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment