-3

I'm new to Android developing.
At the moment I'm trying to fill in a TableLayout with my data.
The Data part works just well but TextView parameters from TableRow don't affect my design.

Here's my Activity whith the table:

<?xml version="1.0" encoding="utf-8"?>

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/table"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:stretchColumns="1">
    <include layout = "@layout/table_row"/>
    </TableLayout>
</ScrollView>

and here's TableRow XML I use to inflate

<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FBFBFB">
    <TextView
        android:id="@+id/number"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:padding="2dp"
        android:layout_weight="0"
        android:textSize="16sp"/>
    <TextView
        android:id="@+id/school_name"
        android:textSize="16sp"
        android:background="@color/colorAccent"
        android:layout_weight="1"
        android:text="School Name"/>
    <TextView
        android:id="@+id/rating"
        android:textSize="16sp"
        android:padding="2dp"
        android:layout_weight="2"
        android:text="Rating"/>
</TableRow>

and Java code:

public void fillTable () {
        TableLayout tableLayout = (TableLayout) findViewById(R.id.table);
        LayoutInflater inflater = LayoutInflater.from(this);
        for(int i = 0; i<schools.size(); i++){
           addRow(i, inflater, tableLayout);
        }

    }

    public void addRow(int num, LayoutInflater inflater, TableLayout parent) {
        TableRow tr = (TableRow) inflater.inflate(R.layout.table_row,parent,false);
        tr.setId(num + 1);
        TextView tv = tr.findViewById(R.id.number);
        tv.setText(String.valueOf(num+1));
        tv =  tr.findViewById(R.id.school_name);
        tv.setText(schools.get(num).schoolName);
        tv =  tr.findViewById(R.id.rating);
        tv.setText(String.valueOf(schools.get(num).score));;
        final int index = num ;
        tr.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainActivity.this, SchoolCard.class);
                intent.putExtra(SCHOOL_LINK,schools.get(index).schoolCardLink);
                startActivity(intent);
            }
        });
       parent.addView(tr);
    }

Can't find where problem is.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Kirill
  • 163
  • 1
  • 10

1 Answers1

0

Place the TableRow inside the Table tab and run.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Vijay Chaudhary
  • 228
  • 2
  • 12