nickk
01/16/2018, 2:39 PMFrameLayout
) in my XML layout and I want to populate it with an unknown number of `TextView`s, programmatically, at runtime.
I tried something like:
placeholder.addView(xxx)
, where xxx is a VerticalLayout created using anko,
but I am getting the Exception:
java.lang.IllegalStateException: The specified child already has a parent
I create the VerticalLayout with this function:
fun createTextViews() : View {
return verticalLayout {
textView {
text = "TextView 1"
}
textView {
text = "TextView 2"
}
}
}
Roxana Nistor
01/16/2018, 2:54 PMnickk
01/16/2018, 2:57 PMRoxana Nistor
01/16/2018, 2:58 PMnickk
01/16/2018, 3:03 PMplaceholder.addView( this.linearLayout { textView("Text 1") })
and I am getting the same Exception.Roxana Nistor
01/16/2018, 3:06 PMnickk
01/16/2018, 3:16 PMfun createView(ui: AnkoContext<Context>): View = with(ui) {
return relativeLayout {
val emptyView = textView("Say something outrageous.") {
textSize = 16f
typeface = Typeface.MONOSPACE
}.lparams {
centerInParent()
}
}
}
Roxana Nistor
01/16/2018, 3:17 PMnickk
01/16/2018, 3:17 PMRoxana Nistor
01/16/2018, 3:17 PMnickk
01/16/2018, 3:17 PMRoxana Nistor
01/16/2018, 3:18 PM