Android: mass enable/disable buttons

Bostone picture Bostone · Jul 8, 2010 · Viewed 9.6k times · Source

I have an activity where a bunch of buttons are placed inside TableLayout, not unlike a dial pad. During some operations I need to temporarily disable the buttons. To my unpleasant surprise doing TableLayout.setEnabled(false) has no effect on the nested buttons. Am I stuck with setting each individual button or is there a nifty (better) way to achieve the same?

Answer

Cristian picture Cristian · Jul 8, 2010

I'd try to do something like this:

TableLayout tableLayoutInstance; // let's suppouse you have already initialized it
// blablabla
// example to deactivate all buttons
ArrayList<View> touchables = tableLayoutInstance.getTouchables();
for(View touchable : touchables){
    if( touchable instanceof Button )
        ((Button)touchable).setEnabled(false);
}