Skip to content

Instantly share code, notes, and snippets.

@Temidtech
Created June 28, 2019 13:48
Show Gist options
  • Save Temidtech/4a928e8fe44ca9fde2f81ab768ed5840 to your computer and use it in GitHub Desktop.
Save Temidtech/4a928e8fe44ca9fde2f81ab768ed5840 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