I have a similar query to the one posted here. I create a grid consisting of a variable number of buttons, at runtime (in a TableLayout), and would like to find the index of the button pressed. The actual Button objects are currently stored in an array, although I'm not sure if that is really necessary. I tried to write the ClickListener using something along the lines of:
public void onClick(View view) {
Button clickedButton = (Button) view;
int buttonID = clickedButton.getId();
but this just always returns -1. Is it possible to get the id (or some other reference to the button pressed) without predefining the buttons in xml?
The solution in the other post describes cycling through the whole array of Buttons and comparing ids. Is there a more elegant way to do this?