I'm new to java/android and would really appreciate help with this. I would like my java method to be able to take in more than one type for the parameter. For example the variable myButton could be an ImageButton or just a Button. The code inside myFunction is valid for whether myButton is an ImageButton or a Button.
if (condition) {
ImageButton myButton = (ImageButton) findViewById(R.id.myButtonID);
myFunction(myButton);
} else {
Button myButton = (Button) findViewById(R.id.myButtonID);
myFunction(myButton);
}
public void myFunction(Button or ImageButton myButton) {
....identical code for myButton which could be an ImageButton or Button....
}
I could obviously write out 2 funcions for parameter type and call it when applicable but that seems like a waste and there must be a quicker way. How can I do this? Thanks for your help.