回调接口转换kotlin语言后的各种坑

我把我的一个项目转换kotlin后,回调接口各种问题一直报错,AdapterView.OnItemClickListener { parent, view, position, id ->这个回调报Warning:(44, 70) Parameter '_parent' is never used, could be renamed to _
Warning:(44, 79) Parameter '_view' is never used, could be renamed to _
Warning:(44, 96) Parameter '_id' is never used, could be renamed to _
我自己定义的回调一直报错:

interface ChapterListener {
fun subChapterResult(subChapterStatu: Boolean)
}

companion object {
var SUB_CHAPTER_RESULT: Boolean = false
private var bookPath: String? = null
private var listener: ChapterListener? = null

@Synchronized fun init(mActivity: Activity, mBookPath: String, mlistener: ChapterListener) {
listener = mlistener
bookPath = mBookPath
//启动分章Service
val chaptersIntent = Intent()
chaptersIntent.setClass(mActivity, ChapterService::class.java)
mActivity.startService(chaptersIntent)
Log.i("service", "service-init--" + mBookPath)
}
}

ChapterService.init(mActivity, bookPath!!){ subChapterStatu -> SUB_CHAPTERS_STATUS = subChapterStatu}
已邀请:

abcdwf

赞同来自: loveJing

写法问题而已,写成object格式的就行了
    fileSelectorb.setOnSelectOkListener(object: FileSelector.OnSelectOkListener{
override fun onSelectOk(fpath: String?) {
...
}
})

 

要回复问题请先登录注册