在使用Kotlin写adapter的setOnItemClickListener事件的时候抛出了kotlin.TypeCastException: null cannot be cast to non-null type android.widget.TextView的异常,出错代码如下:
错误代码:
(adapter.getViewByPosition(index,R.id.tv_menu_name) as TextView).textSize = 12f
正确写法:
adapter.getViewByPosition(index,R.id.tv_menu_name)?.findViewById<TextView>(R.id.tv_menu_name)?.textSize = 12f