0

I have a list of Button objects that I use to enable/disable all buttons at once. I use the following very simple code:

void buttonsEnabled(boolean enabled)
{
    for(Button btn : buttonList)
    {
        btn.setEnabled(enabled);
    }
}

Is it possible to add a ToggleButton into the ArrayList buttonList, since it inherits from CompoundButton which inherits from Button, or is my thinking mixed up?

1 Answer 1

1

Yes.

java.lang.Object
   ↳    android.view.View
       ↳    android.widget.TextView
           ↳    android.widget.Button
               ↳    android.widget.CompoundButton
                   ↳    android.widget.ToggleButton

If your ArrayList is an ArrayList of Button, you can put a ToggleButton.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, this is the exact thing I checked before trying. It didn't work as expected (the button was not enabled) so I thought I'd ask. I may have just found out why, though.
If you need more help, post the code where you create ArrayList, and where you add togglebuttons/buttons

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.