I have tried using the code mentioned in the link below to "mass disable" buttons and it works perfectly fine. However the same code does not work for mass enable.
Android: mass enable/disable buttons
Code for Disable (Working)
TableLayout tl = (TableLayout)findViewById(R.id.table1); //
ArrayList<View> touchables = tl.getTouchables();
for(View touchable : touchables){
if( touchable instanceof Button && touchable != btnNewWord )
((Button)touchable).setEnabled(false);
}
CODE for Enable (Not Working)
btnNewWord.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
TableLayout tl = (TableLayout)findViewById(R.id.table1);
ArrayList<View> touchables = tl.getTouchables();
for(View touchable : touchables){
if( touchable != btnNewWord )
((Button)touchable).setEnabled(true);
}
Once you set the buttons disabled,i think,they will no longer be touchable. So you need to modify that point in your code and use something else to get all views. You can preserve your ArrayList
which you used to disable buttons and then use the same to re enable them.
EDIT :
Try this:
ArrayList<View> touchables //declare globaly
then
TableLayout tl = (TableLayout)findViewById(R.id.table1); //
touchables = tl.getTouchables();
for(View touchable : touchables)
{
if( touchable instanceof Button && touchable != btnNewWord )
((Button)touchable).setEnabled(false);
}
and now,
btnNewWord.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
for(View touchable : touchables)
{
if( touchable != btnNewWord )
((Button)touchable).setEnabled(true);
}
}
}