0

I am new to android. I have need to display arrays values of alphabets (A-Z) as buttons, but if i use the linear layout,the buttons are displayed in a linear line which cause the many buttons cannot be seen in the layout. Please help me so that the buttons are visible using the table layout. T

enter image description here

Here is my code:

public class Alphabet extends Activity{

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        //LinearLayOut Setup
        LinearLayout linearLayout= new LinearLayout(this);
        linearLayout.setOrientation(LinearLayout.HORIZONTAL);

        linearLayout.setLayoutParams(new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));


        //TableLayout Setup
        TableLayout tableLayout = new TableLayout(this);
        tableLayout.setOrientation(tableLayout.HORIZONTAL);

        linearLayout.setLayoutParams(new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));

        List<String> alpha = Arrays.asList("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",
                "U", "V", "W", "X", "Y", "Z");

        for(String item : alpha ){
            System.out.println(item);
            Button btn = new Button(this);
            btn.setText(item);
            btn.setLayoutParams(new ViewGroup.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT));
            linearLayout.addView(btn);
        }

        setContentView(linearLayout);
    }

}   
Brian Tompsett - 汤莱恩
  • 5,438
  • 68
  • 55
  • 126
Chrisantics
  • 155
  • 2
  • 16

0 Answers0