1
我正在做一个listview什么时候点击调用函数。Kotlin中的异步匿名函数? (lambda表达式)
和I want to get function is async or sync
。
当它是异步时阻止。我想知道how attach async mark to kotlin lambda expression
。
class FunctionCaller_Content(text: List<String>,
val function: List< /*suspend? @async? */
( () -> Unit )?
>? = null)
/* I want both of async, sync function. */
{
fun isAsnyc(order: Int): Boolean
= // how to get this lambda expression{function?.get(order)} is async?
fun call(callerActivity: Activity, order: Int) {
val fun = function?.get(order)
fun()
if(isAsync(fun))
/* block click for async func */
}
}
和用法。
FunctionCaller_Content(listOf("Click to Toast1", "Click to Nothing"),
listOf(
{
Toast.makeText(this, "clicked", Toast.LENGTH_SHORT)
},
{
/*if async lambda expression, how can i do?*/
})
谢谢。你帮了我很多。但它在UI线程上。所以我必须尝试阻止点击。以及如何获得'''isAsync()'''''如果我使用List'''????不可能??我尝试'''如果(func是(suspend() - > Unit)''',它不起作用.... –
并且这段代码不起作用。T_T ...因为run {}是内嵌的所以它不会返回'''() - > Unit''' –
请参阅编辑另一个替代方案 –