class TodoActivity: AppCompatActivity() {
var id = 0L
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_todo)
setSupportActionBar(toolbar1)
val taskList = ArrayList<Task>()
val task1 = Task(id++, "Task", "Make awesome Tasks", Date())
taskList.add(task1)
recyclerView.layoutManager = LinearLayoutManager(this)
recyclerView.adapter = TaskAdapter(taskList) {
toast("${it.title}Clicked")
}
fab.setOnClickListener {
taskList.add(Task(id++, "Task${id}", "Description for Task ${id}", Date()))
recyclerView.adapter.notifyDataSetChanged()
}
if (taskList.size > 0)
tvNotTask.visibility = View.GONE
else
tvNotTask.visibility = View.VISIBLE
}
private fun toast(msg: String) = Toast.makeText(this, msg, Toast.LENGTH_LONG).show()
}
这是我的代码,当我想运行我的应用程序时,出现以下错误
不可能将其强制转换为“ TaskAdapter”,因为“ recyclerView.adapter”是一个复杂的表达式
有人知道该怎么做吗,如果您需要了解那里的信息,我也可以添加布局文件