E
E
Edward2016-09-15 22:15:49
Java
Edward, 2016-09-15 22:15:49

How to form a normal table?

I don’t know how to form a table, I tried TableLayout

protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  stroka = (TextView) findViewById(R.id.info);
  TableLayout tableLayout = new TableLayout(this);
  tableLayout.setLayoutParams(new TableLayout.LayoutParams(
   ViewGroup.LayoutParams.FILL_PARENT,
   ViewGroup.LayoutParams.WRAP_CONTENT
  ));
  tableLayout.setStretchAllColumns(true);
  try {
   TextView textView[] = new TextView[9];
   TableRow tableRow[] = new TableRow[3];
   for (int i = 0; i < 9; i++) {
    textView[i] = new TextView(this);
    textView[i].setText("Stroka " + i);
   }

   int l = 0;
   for (int i = 0; i < 3; i++) {
    tableRow[i] = new TableRow(this);
    for (int j = 0; j < 3; l++, j++) tableRow[i].addView(textView[l]);
   }
   for (int i = 0; i < 3; i++) {
    tableLayout.addView(tableRow[i]);
   }
   setContentView(tableLayout);
  }

But the problem is that the same number of rows and columns are created, and I need a table with 4 rows and 7 tables. Tell me which way to dig.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question