Hi guys, I'm new to the forums.
The first thing I did was use the search function and after 10 pages I could not see what I was looking for. So I'm going to give this a shot.
In java, we use method parameters for a number of reasons but I've never used parameters in my methods unless I needed them
When defining a method in android for a button that I want to click, I had my method defined in XML under the Button element
[HIGH]android
nClick="showText"[/HIGH]
then, in my ProjectName.java file I defined the method
[HIGH]public void showText(View view){
}[/HIGH]
The View parameter is never used by me.. I have no need for it.
By asking questions on Stackoverflow I was told that the View in the parameter is the view that was clicked.
Button is a subclass of View as is TextView and since that is the case, that answer sort of makes sense.
But the question I have is.... is this the rule for just the onClick method?
Also, why can I not pass the Button as a parameter? Button is the actual "View" being clicked, so why not Button?
Furthermore, are there other methods similar to this and if so, do they all follow the rule just like the View parameter, where let's say if I had a class called "A" and it had a subclass "B" and that class had a subclass "C", and if I wanted to use the onClick method, I can only pass the Highest Class as the parameter?
To simplify that, are there ever cases where I would pass anything else OTHER THAN "View" as the parameter to these methods?
Thank you.
The first thing I did was use the search function and after 10 pages I could not see what I was looking for. So I'm going to give this a shot.
In java, we use method parameters for a number of reasons but I've never used parameters in my methods unless I needed them
When defining a method in android for a button that I want to click, I had my method defined in XML under the Button element
[HIGH]android
nClick="showText"[/HIGH]then, in my ProjectName.java file I defined the method
[HIGH]public void showText(View view){
}[/HIGH]
The View parameter is never used by me.. I have no need for it.
By asking questions on Stackoverflow I was told that the View in the parameter is the view that was clicked.
Button is a subclass of View as is TextView and since that is the case, that answer sort of makes sense.
But the question I have is.... is this the rule for just the onClick method?
Also, why can I not pass the Button as a parameter? Button is the actual "View" being clicked, so why not Button?
Furthermore, are there other methods similar to this and if so, do they all follow the rule just like the View parameter, where let's say if I had a class called "A" and it had a subclass "B" and that class had a subclass "C", and if I wanted to use the onClick method, I can only pass the Highest Class as the parameter?
To simplify that, are there ever cases where I would pass anything else OTHER THAN "View" as the parameter to these methods?
Thank you.