Android: mass on / off buttons

I have activity when a bunch of buttons is placed in a TableLayout, unlike a dial pad. During some operations, I need to temporarily disable the buttons. To my unpleasant surprise, executing TableLayout.setEnabled(false) does not affect the nested buttons. Am I stuck in installing each individual button or is there a great (best) way to achieve the same?

+6
android button tablelayout
source share
3 answers

I would try to do something like this:

 TableLayout tableLayoutInstance; // let 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); } 
+9
source share

I think you need to disable each of these buttons. To make it look a little better, you could put all the buttons in a list and iterate over them during activation and deactivation. But that does not stop you from finding them all the time in your code.

+1
source share

Since the buttons are nested under TableLayout, they need to be easily sorted through the children and set each of them. I do not know if there is an easier way.

0
source share

All Articles