Skip to content

Instantly share code, notes, and snippets.

@AaronC81
Created July 22, 2016 19:03
Show Gist options
  • Save AaronC81/b437933bae2051cd859333d05f426468 to your computer and use it in GitHub Desktop.
Save AaronC81/b437933bae2051cd859333d05f426468 to your computer and use it in GitHub Desktop.
Anko Fragments
inline fun ViewManager.frag(noinline fragment: () -> Fragment, theme: Int = 0, init: View.() -> Unit, fragInit: Fragment.() -> Unit): RelativeLayout {
var parentToFragment: RelativeLayout? = null
val childFragment = fragment()
childFragment.fragInit()
return ankoView({
parentToFragment = RelativeLayout(it)
parentToFragment!!.id = 123123 // TODO: Replace with real ID
(it as Activity).fragmentManager.beginTransaction().add(parentToFragment!!.id, childFragment).commit()
parentToFragment!!
}, theme, init)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment