I need that when the application starts, a method is called that adds an array of buttons to the screen, which is in a separate class. I tried differently, it turns out only to add each button separately and set text for each one manually. Through for-flies the application. PS I will be very grateful for the help! =) Here is what I got:

## Class Button ##

public class ButtonFace { public Button[] numButtonFace; public void setNumButtonFace(){ numButtonFace = new Button[10]; String[] buttonFace = new String[10]; buttonFace[0] = "A"; buttonFace[1] = "B"; buttonFace[2] = "H"; buttonFace[3] = "F"; buttonFace[4] = "C"; buttonFace[5] = "E"; buttonFace[6] = "D"; buttonFace[7] = "S"; buttonFace[8] = "W"; buttonFace[9] = "Q"; for (int i =0; i<numButtonFace.length; i++){ numButtonFace[i].setText(buttonFace[i]); } } 

## OnCreate ##

 protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); LinearLayout top = (LinearLayout) findViewById(R.id.top); Button newLayout = new Button (this); Button newButton = new Button(this); ButtonFace face = new ButtonFace(); face.numButtonFace[0] = new Button(this); newButton.setText("A"); newLayout.setText("V"); top.addView(newLayout,params); top.addView(newButton,params); top.addView(face.numButtonFace[0]); } 

  • Why don't you use an adapter? - Andriy Martsinkevych
  • use listview - wlad
  • Probably because I do not know how to implement otherwise, so I ask here. Wlad, thanks for the tip! - Mikhail Shaydulin

0