0

I have a TableLayout declared in a XML File, it will show scores, and these scores are added via rows programmatically. The problem is that the layout without any score added looks like this (As it should be):

Correct

But when a score's row is added, it looks like this:

Wrong

I can’t understand why this is happening, I would like to see the columns well stretched and there’s no apparent reason that explains this behavior. If anyone can help me i'll be very grateful.

Thanks in advance and sorry for my english.

Here is my XML and my code:

XML:

<TableLayout xmlns...
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:stretchColumns="*"
android:layout_column="5"
android:id="@+id/scoresTable">
    <TableRow
        android:layout_gravity="center_horizontal"
        android:id="@+id/titleScoresRow"
        android:layout_height="42dp">
        <TextView
            android:id="@+id/scoresTitle"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:text="Best Scores"
            android:layout_span="5"
            android:gravity="center"
        />
    </TableRow>
    <TableRow
        android:layout_gravity="center_horizontal"
        android:id="@+id/firstRow"
        android:layout_height="42dp">
        <TextView
            android:id="@+id/MODE"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:text="MODE"
            android:gravity="center"
            />
        <TextView
            android:id="@+id/KANA"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:text="KANA"
            android:gravity="center"
            />
        <TextView
            android:id="@+id/DIFF"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:text="DIFF"
            android:gravity="center"
            />
        <TextView
            android:id="@+id/SCORE"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:text="SCORE"
            android:gravity="center"
            />
        <TextView
            android:id="@+id/DATE"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:text="DATE"
            android:gravity="center"
            />
    </TableRow>

Activity:

 TableLayout table = (TableLayout) findViewById(R.id.scoresTable);
    createOrderedCSV(getApplicationContext(), 4, ":");
    ArrayList<String> scores = readScores("OrderedScoresCSV.csv");
    // Score rows
    for (int i = scores.size() - 1; i >= 0; i--) {
        String[] currentScore = scores.get(i).split(":");
        TextView mode = new TextView(this);
        mode.setText(currentScore[0]);
        TextView kana = new TextView(this);
        kana.setText(currentScore[2]);
        TextView diff = new TextView(this);
        diff.setText(currentScore[1]);
        TextView score = new TextView(this);
        score.setText(currentScore[4]);
        TextView date = new TextView(this);
        date.setText(currentScore[3]);

        TableRow row = new TableRow(this);
        row.addView(mode);
        row.addView(kana);
        row.addView(diff);
        row.addView(score);
        row.addView(date);
        table.addView(row, new TableLayout.LayoutParams(
                TableLayout.LayoutParams.FILL_PARENT,
                TableLayout.LayoutParams.WRAP_CONTENT));
    }
    TableRow buttonRow = new TableRow(this);
    Button eraseScores = new Button(this);
    eraseScores.setWidth(200);
    eraseScores.setHeight(60);
    eraseScores.setText("Erase Scores");
    buttonRow.setGravity(Gravity.CENTER_HORIZONTAL);
    buttonRow.addView(eraseScores);
    table.addView(buttonRow);
PerroVerde
  • 49
  • 8

1 Answers1

0

It was caused by the button row that I added at the end. It was attached to the first column.

Infinite Recursion
  • 6,511
  • 28
  • 39
  • 51
PerroVerde
  • 49
  • 8