Thank you. I knew there had to be a way.
Mark Murphy wrote:
Try Resources#getIdentifier().Ok, here's the problem. I have a layout file with 25 ImageButtons in in laid out in a 5x5 grid. During my application setup, I need to go through and add onClick and onLongClick handlers to each button and add the buttons to a local array. The problem is, I don't want to explicitly name every button in code. It's error prone. I want to do this setup in a loop. I thought I could do something like the following: int buttonBaseId = com.pingo.R.Id.button00; ImageButton button = null; for (int i = 0; i < R.attr.GRID_SIZE; ++i) { for (int j = 0; j < R.attr.GRID_SIZE; ++j) { button = (ImageButton) findViewById(buttonBaseId++); setupButton(button,i,j); } } But that doesn't work. I get the error: Description Resource Path Location Type The type com.pingo.R$Id cannot be resolved. It is indirectly referenced from required .class files Main.java /Pingo/src/com/pingo line 1 Java Problem What I would prefer would be some way to get the buttons like: int buttonBaseId = com.pingo.R.Id.button00; ImageButton button = null; for (int i = 0; i < R.attr.GRID_SIZE; ++i) { for (int j = 0; j < R.attr.GRID_SIZE; ++j) { String idString = "button" + i + j; button = (ImageButton) findViewByIdString(idString); setupButton(button,i,j); } } Suggestions? Thanks, Ray
-- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

