Kotlin未解析的引用和类函数未出现在自动选择中

时间:2020-08-12 17:12:01

标签: android kotlin

我正在尝试遵循本教程:https://www.youtube.com/watch?v=0_gtvFtZjQ8

(这是科特林的数独游戏)

我有我的第一堂课:SodokuBoardView,它具有以下功能:

fun updateSelectedCellUI(row: Int, col: Int) {
    selectedRow = row
    selectedCol = col
    invalidate()
}

fun registerListener(listener: SodokuBoardView.OnTouchListener) {
    this.listener = listener
}

interface OnTouchListener {
    fun onCellTouched(row: Int, col: Int)
}

在另一个类PlaySodokuActivity中,我尝试使用updateSelectedCellUI和registerListener,但是获得了对它们的未解析引用。

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_play_sudoku)

        SodokuBoardView.registerListener(this)

        viewModel = ViewModelProviders.of(this).get(PlaySodokuViewModel::class.java)
        viewModel.sodokuGame.selectedCellLiveData.observe(this, Observer{ updatedSelectedCellUI(it) })
    }


    private fun updatedSelectedCellUI(cell: Pair<Int, Int>?) = cell?.let {
        SodokuBoardView.updateSelectedCellUI(cell.first, cell.second)
    }

自动完成功能甚至找不到它们。 (但是它确实找到了SodokuBoardView.OnTouchListener

AutoComplete when typeing SodokuBoardView. into a function in PlaySodokuActivity.kt

Build Failed Errors

我想念什么?我做了很多搜索,但是对于Kotlin来说还是很新的。

0 个答案:

没有答案