I'm working through the android developer tutorial and we're now creating a method to match to the method name we gave to android:onClick="sendMessage".
Here's the method:
/** Called when the user clicks the Send button */
public void sendMessage(View view) {
// Do something in response to button
}
The text says this about the method:
In order for the system to match this method to the method name given to android:onClick, the signature must be exactly as shown. Specifically, the method must:
- Be public
- Have a void return value
- Have a View as the only parameter (this will be the View that was clicked)
I understand why it must be public and why the return value is void, but why does the method take (View view) instead of just (view)? I'm coming from a Ruby background so the syntax is confusing me. Why do we pass parameters like this?
view, you would not know the Object type, you always need the Object type of the parameters in a method.