Reputation: 1
When I try to change the property of the Button (onClick) no the drop downlist is empty and I receive errors when adding the sendMessage (view; View)
Method. See below the assigment:
*In the file app > java > com.example.myfirstapp > MainActivity
, add the sendMessage() method stub as shown below:
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
/** Called when the user taps the Send button */
fun sendMessage(view: View) {
// Do something in response to button
}
}
You may see an error because Android Studio cannot resolve the View class used as the method argument. So click to place your cursor on the View declaration, and then perform a Quick Fix by pressing Alt + Enter (or Option + Enter on Mac). (If a menu appears, select Import class.)
Now return to the activity_main.xml
file to call this method from the button:
Click to select the button in the Layout Editor.
In the Attributes window, locate the onClick property and select sendMessage [MainActivity] from the drop-down list (THIS DOES NOT APPEAR??).
Now when the button is tapped, the system calls the sendMessage() method.*
Upvotes: 0
Views: 953
Reputation: 1
I had the same problem with java version of the tutorial. (That's how I found this thread.) Just in case someone else runs in this problem:
Upvotes: 0
Reputation: 1
You need to write the sendMessage function in Jave syntax and that's it
Try replacing the sendMessage with the code below and then you should be able to view the senMessage
public void sendMessage(View view) {
}
Upvotes: 0
Reputation: 51
For those that come back to this, try switching to JAVA instructions rather than KOTLIN, this then worked for me!
Upvotes: 1