There is an array of Button assigned to each button id. But now how to apply for this id?


while (i < 10){ face.numButtonFace[i].setText(face.but[i]); face.numButtonFace[i].setId(View.generateViewId()); i++; } 


The fact is that when you reload the page id changes again

  • Yes, no difference, in the array of 10 buttons. it will fit only 1 button, but not the array - Mikhail Shaydulin
  • What do you need to do with these id? - katso 4:08 pm
  • Transfer to the Onclick method, specifically to the switch statement - Mikhail Shaydulin
  • "The fact is that when you reload the page, the id changes again." because your $ i = 0 is written in the code (most likely). here it is reset. - Wlad

1 answer 1

 Button btn = (Button) findViewById(face.numButtonFace[i].getId()); 
  • while not so good, only the last button will be duplicated - Mikhail Shaydulin
  • Why not use a for loop? - Roman Shubenko
  • You asked how to apply, here's an example of your treatment. Put any number instead of i. - yno7 pm