3

How do I store a layout created via ViewManager in a variable and pass it to another function without it rendering whilst being stored in the said variable

Example Code

1) The spinner Layout

fun ViewManager.spinnerLayout(
        spinner: Spinner
) = linearLayout {

    lparams(width = matchParent) { weightSum = 2.toFloat() }

    textView {
        textSize = 18f
        textColor = colorWhite
        text = "tested"
    }.lparams{ weight = 1.toFloat() }

    spinner.lparams{ weight = 1.toFloat() } // The spinner is rendered here

}

2) The spinner itself

fun ViewManager.spinner() = spinner {
    id = R.id.mySpin 
    prompt = "Select A Option"
}

The problem is that if I use the below code to call the spinner() and pass that variable to the spinnerLayout() function, the spinner is echoed twice. So, I want to know how do I store it in the variable without it rendering

mySpinner = spinner() // It renders here
spinnerLayout(mySpinner) // and here
Rajat Jain
  • 1,339
  • 2
  • 16
  • 29
Dev Man
  • 2,114
  • 3
  • 23
  • 38
  • why you use 3 time `lparams` in your function? – David Jun 17 '18 at 08:50
  • Have a look here how the view is saved: https://stackoverflow.com/questions/50743867/anchor-suggestionpopup-to-textview. Don't know if it'S helping, never being active in android-programming. – David Jun 17 '18 at 09:06
  • 1
    @David the link you have provided is no doubt helpful but only if my project were using standard Android xml layouts, the solution you've shown dosen't help with anko layouts – Dev Man Jun 17 '18 at 12:30

0 Answers0