Hi all! I'm having trouble calling a function from...
# coroutines
t
Hi all! I'm having trouble calling a function from a
Coroutine
that is inside a custom
ViewHolder
The function is not recognised, and when I put it in the
ViewHolder
class, of course I can't calll the `add`/`remove` functions anymore.. Could you point me in the right direction please? Here is the basic setup:
Copy code
class MyAdapter() : RecyclerView.Adapter<MyViewHolder>()
{
    fun add() {}
    fun remove() {}
    [...]

    /* Custom ViewHolder */
    class MyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView)
    {
        fun bind(item: Item) = with(itemView)
        {
            /* Handle long click event on row*/
            isLongClickable = true
            onLongClick { function() } // I'M HAVING TROUBLE HERE (Unresolved reference)
       
            [...]
        }
    }

    /* How to call this? */
    fun function() {
        add()
        remove()
    }
Thanks for the help! 🙂
v
Where is any
Coroutine
-related things?
r
@trubesv where you couroutine? Could you paste you code in online editor? So I can see full code.
t
@vlastachu @radityagumay Sorry I might have used the wrong term, the `onLongClick`seems to be considered as a
CoroutineScope
, IntelliJ suggests me to create an extension function it so I can call
function
, like
fun CoroutineScope.function() {}
k
@trubesv make
MyViewHolder
an
inner class
t
@kevinherron Wow ty good sir! I'll look more into this concept, thanks 🙂
in Java that would have been an inner class by default. in Kotlin it needs to be made inner explicitly
t
I'll keep that in mind! Thanks for the explanation.