1

I have an Android app (Written in Android Studio) which I'm trying to streamline. Basically, 10 buttons on the same screen each with a unique id of "button1" through "button10".

My question regards findViewById. I understand that it takes an integer as its argument and I can get it to work using findViewById(R.id.button1) etc but how can I make the R.id.button1 part generic? Eg How could I incorporate the R.id.button1 part into a For loop so that I could change the text on all the buttons programatically? I've tried constructing the argument part via something like "R.id.button" + z + "" (Where z loops from 1 to 10) but then the argument isn't integer. What am I missing?

Many thanks for any help...

Simon

SMD
  • 31
  • 3
  • This is a duplicate, the answer on this page looks like exactly what you need: http://stackoverflow.com/questions/4809834/how-to-iterate-through-a-views-elements (except you would do "v instanceof Button") – Baronz Feb 08 '16 at 19:31

0 Answers0