Albus Dumbledore
Albus Dumbledore

Reputation: 12616

TableLayout in Android

I have several distinct View objects, stored in the views array, that I want to show together on the screen. Therefore, as far as I understand it correctly, a TableView would do exactly that. However, I can only see one of the views, i.e. like there is a single row, not to rows. Here goes my code:

class myApp extends Activity {

    FrameLayout mainFrame = ...;
    View[] views = ...;

    ...

    TableLayout grid = new TableLayout(this);

    for (int i = 0; i < views.length; i++) {
        TableRow row = new TableRow(this);
        row.addView(views[i]);
        grid.addView(row);//, i);
    }

    mainFrame.addView(grid, 1);

UPDATE

Turns out the previous code actually didn't show anything.

I can see something only if I don't use TableRow, but then I'd get one row only, i.e.:

class myApp extends Activity {

    FrameLayout mainFrame = ...;
    View[] views = ...;

    ...

    TableLayout grid = new TableLayout(this);

    for (int i = 0; i < views.length; i++) {
        grid.addView(views[i]);
    }

    mainFrame.addView(grid, 1);

Any help would be highly appreciated! Thanks!

Upvotes: 0

Views: 519

Answers (1)

Vivienne Fosh
Vivienne Fosh

Reputation: 1778

Try using

grid.setOrientation(TableLayout.VERTICAL)

Upvotes: 1

Related Questions