I want to call a method, but the parameter can be Button or ImageButton. I call the method two times with different types of parameters as with objects.
In my attributesOfButton method, I want to assign the appropriate button type, as in the code below.
private void memCheck()
{
ImageButton imageButtonCam;
Button buttonCamCo;
attributesOfButton(imageButtonCam);
attributesOfButton(buttonCamCo);
}
private void attributesOfButton(Object button)
{
Object currentButton;
if (button instanceof ImageButton)
{
currentButton = (ImageButton) button;
}
if (button instanceof Button )
{
currentButton = (Button) button;
}
if (Provider.getValue == 1) {
currentButton.setEnabled(true);
}
}
But that will not work. If I, for example, do this:
currentButton.setEnabled(true);
I get
Cannot resolve setEnabled (boolean) method
Maddy source
share