Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: mass enable/disable buttons

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?

like image 765
Bostone Avatar asked Jul 08 '10 15:07

Bostone


2 Answers

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);
}
like image 174
Cristian Avatar answered Sep 19 '22 04:09

Cristian


I think you have to set each individual of this Buttons to deactivated. To make it look a little bit nicer you could put all of the buttons in a list and iterate over them during activating and deactivating. But this will not prevent you from finding them all once in you code.

like image 37
Janusz Avatar answered Sep 20 '22 04:09

Janusz