I have the following code and am getting an error with the Intent. It is because of the this
I am fairly certain.
listView.onItemClickListener = object : OnItemClickListener {
override
fun onItemClick(parent: AdapterView<*>, view: View,
position: Int, id: Long) {
val intent = Intent(this, MyActivity::class.java)
startActivity(intent)
}
}
It has two solutions you can use either:
val intent = Intent(this@YourActivity, MyActivity::class.java)
startActivity(intent)
or :
val intent = Intent(applicationContext, MyActivity::class.java)
startActivity(intent)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments