Issue
Hey guys I created a spinner with three options. Now I want the user to decide for one option. Then the user should be directed to the fitting activity. But I get an error by adding an Intent method to the on Item selected. So it "Doesn't know" the function type
option.onItemSelectedListener = object: AdapterView.OnItemSelectedListener {
override fun onItemSelected(p0: AdapterView<*>?, p1: View?, p2: Int, p3: Long) {
result.text = options.get(p2)
if (options.get(p2) == "3 Rounds") {
val intent = Intent(this, Settings::class.java)
startActivity(intent)
}
}
override fun onNothingSelected(p0: AdapterView<*>?) {
result.text = "Please Select"
}
}
When I press Alt + Enter it just says to create a function.
Solution
In Kotlin you have to mention your Activity name after this
keyword followed with@
val intent = Intent(this@YourActivity, Settings::class.java)
Answered By - Sniffer
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.