I got it working with this change:
for (int i = 0; i < 5; i++) {
Button button = new Button(getApplicationContext());
button = new Button(getApplicationContext());
button.setId(i+1);
button.setText("" + i);
relativelayout.addView(button);
bList[i] = button;
}
button.setId(i+1);
I can't find it in the docs, but maybe when you make a new View programmatically, the default NO_ID equals 0
?