我为我的RecyclerView设置了一个ItemClickLister,如下所示:
ItemClickSupport.addTo(recyclerView!!).setOnItemClickListener(
object : ItemClickSupport.OnItemClickListener {
override fun onItemClicked(recyclerView: RecyclerView?, position: Int, v: View?) {
val row = recyclerView!!.getChildAt(position)
val el = row.findViewById(R.id.active_expandablelayout) as ExpandableLayout
if (el.isExpanded) {
el.collapse()
} else {
el.expand()
}
}
}
)
Run Code Online (Sandbox Code Playgroud)
使用我翻译成Kotlin的ItemClickSupport库.
我在object(第2行)上收到错误消息:
object必须声明为abstract或实现抽象成员.
我是Kotlin的新手,我也找不到任何解决方案.
任何帮助是极大的赞赏.
编辑:
这是我的ItemClickSupport.kt:
class ItemClickSupport private constructor(private val mRecyclerView: RecyclerView) {
private var mOnItemClickListener: OnItemClickListener? = null
private var mOnItemLongClickListener: OnItemLongClickListener? = null
private val mOnClickListener = View.OnClickListener { v ->
if (mOnItemClickListener != null) …Run Code Online (Sandbox Code Playgroud) 为什么我可以在课堂上使用Lambda java.lang.Thread,但不能用于MyThread?
interface MyRunnable{
fun run()
}
class MyThread(runnable : MyRunnable){
}
fun test(){
Thread({}) // All Alright
MyThread({}) //Exception. Type mismatch <<-- Why ?
}
Run Code Online (Sandbox Code Playgroud)
链接检查此示例:https://try.kotlinlang.org/#/UserProjects/tbs79qfkh50psp7r3qrdrinrmt/sfkpjq1bjvg4r6d5rmnu6mp4a8