I have 9 (programmatically generated) buttons. I do this for all of them:
Button btnButton1 = new Button(this);
btnButton1.setText(getText(R.string.button_1));
btnButton1.setTextSize(BUTTON_TEXT_SIZE);
btnButton1.setHeight(BUTTON_HEIGHT);
btnButton1.setWidth(BUTTON_WIDTH);
btnButton1.setOnClickListener(buttonClicked(btnButton1));
(where buttonClicked is this:
private final View.OnClickListener buttonClicked(final Button button)
{
return new View.OnClickListener()
{
public void onClick(View v)
{
tvButtons.append(button.getText().toString());
}
};
};
and tvButtons is a TextView. )
Is there a way I can do something like:
for (button : buttons)
{
button.setText &c. &c.
}
to reduce the duplication in the code?