Home > Software design >  How to insert a parameter in a function that is inside other functions in Kotlin
How to insert a parameter in a function that is inside other functions in Kotlin

Time:05-26

I have a function which receives a MutableList parameter, which is inside other functions. But this last function does not accept it.

ObtenerUsuarios{ :Adaptador{::LecturaFacturas{::createRecyclerViewA(listdeClientsString) }}} 

When I insert the parameter in createRecyclerViewA it says :this sintax is reserverd for future use...

    fun crearRecyclerViewA(ListDatosX: MutableList<String>){

    var adapter = RecyclerAdapter(ListDatosX)
    recyclerA.adapter=adapter

    adapter.setOnClickListener {
        // Toast.makeText(getApplicationContext(), "${ListDatos.get(recycler.getChildAdapterPosition(it))}", Toast.LENGTH_SHORT).show() //
        var posicion :Int =recyclerA.getChildAdapterPosition(it)
         println("$posicion    esta es la variable posicion")
        VerEnPantalla(posicion) // Despliega opciones para realizar aprobar pago
    }
}

CodePudding user response:

::createRecyclerViewA isn't a function call, it's a function reference - a way of referring to a function as a thing you can pass around. You can't add () onto the end - if you want to call the function, you have to use invoke(params) on the reference

::createRecyclerViewA.invoke(listdeClientsString)

I don't know why you want to do that if you're invoking it right there - just call the function normally, createRecyclerViewA(listdeClientsString). But if you are passing function references around, that's how you invoke them

  • Related