Reputation: 83
I have a grid with lots of buttons in it, is it possible to disable the grid which would lead to all the buttons to being disabled?.
The reason why is after the use clicks a button to answer the question, the answer is checked and scores etc calculated, but if i keep pressing a button while this is happening it keeps answering the next question and so on even when i use a handler to wait. The disable is only temporary they are enabled again after everything is calculated.
How do i stop this? without having to disable every single button manually.
Thanks in advance.
Edit:
GridLayout numgrid = (GridLayout) findViewById(R.id.numbersGrid);
GridLayout lettergrid = (GridLayout) findViewById(R.id.lettersGrid);
numgrid.setEnabled(false);
lettergrid.setEnabled(false);
I tried the above code doesn't work as i need it too.
Upvotes: 0
Views: 1092
Reputation: 3457
Apparently there does not seem to be an "easy" way to solve this. What you can do is grab all buttons in your layout as an array, then loop through them. Something like the following method which disables all buttons in a GridLayout:
private void disableButtons(GridLayout layout) {
// Get all touchable views
ArrayList<View> layoutButtons = layout.getTouchables();
// loop through them, if they are an instance of Button, disable it.
for(View v : layoutButtons){
if( v instanceof Button ) {
((Button)v).setEnabled(false);
}
}
}
Then simply pass in your grid layouts:
GridLayout numGrid = (GridLayout) findViewById(R.id.numbersGrid);
GridLayout letterGrid = (GridLayout) findViewById(R.id.lettersGrid);
disableButtons(numGrid);
disableButtons(letterGrid);
Upvotes: 2