I am making an Android application where there is a view consisting of hundreds of buttons, each of which has a specific callback. Now, I would like to set these callbacks using a loop, instead of writing hundreds of lines of code (for each of the buttons).
My question is: how can I use findViewById without static input of each button id? Here is what I would like to do:
for(int i=0; i<some_value; i++) { for(int j=0; j<some_other_value; j++) { String buttonID = "btn" + i + "-" + j; buttons[i][j] = ((Button) findViewById(R.id.buttonID)); buttons[i][j].setOnClickListener(this); } }
Thanks in advance!
android button clicklistener
user573536 Feb 01 '11 at 16:35 2011-02-01 16:35
source share