I programmatically am creating buttons as depending on certain factors their will either be 3 or 4 buttons.
In some instances I would like to create all of the buttons but disable them all. At the moment the problem I have is that I cannot access the buttons from outside of this loop
if (4val != null && 4val.length() > 0){
Button b4 = new Button(this);
b4.setText(answer4val);
b4.setTextSize(18);
layout.addView(b4, layoutParams);
b4.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
reason(4);
}
});
}
I would like to disable / enable all of the buttons outside of these if statements. Is this possible?
Declare them in a wider scopre (maybe as class members):