Last active
July 23, 2016 07:58
-
-
Save AaronC81/02a9f76730698a17ea3718bb4e2b2acd to your computer and use it in GitHub Desktop.
Anko Fragments v2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FragmentView(ctx: Context) : RelativeLayout(ctx) { | |
var childFragment: Fragment? = null | |
get() = field | |
set(value) { | |
field = value | |
if (field == null) { return } | |
(context as Activity).fragmentManager.beginTransaction().add(id, field).commit() | |
} | |
init { | |
this.id = View.generateViewId() | |
} | |
} | |
inline fun ViewManager.fragmentView(theme: Int = 0) = fragmentView(theme) {} | |
inline fun ViewManager.fragmentView(theme: Int = 0, init: FragmentView.() -> Unit) = ankoView({ FragmentView(it) }, theme, init) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Requires API 17 or above due to
View.generateViewId()