Mark Mark - 1 year ago 57
Android Question

Table in Android what am I doing wrong?

I don't get any error, but its not showing anything in the simulator. I want a dynamic table...

Content of the xml file:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="0,1"
android:id="@+id/maintable" >

</TableLayout>


Code in the activity to add the tablerows and textviews:

TableLayout tl = (TableLayout) findViewById(R.id.maintable);

// Go through each item in the array
for (int current = 0; current < strAuftraege.length; current++)
{
// Create a TableRow and give it an ID
TableRow tr = new TableRow(this);
// tr.setId(100+current);
tr.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));

// Create a TextView to house the name of the province
TextView labelTV = new TextView(this);
// labelTV.setId(200+current);
labelTV.setText(strAuftraege[current][0]);
// labelTV.setTextColor(Color.BLACK);
labelTV.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
tr.addView(labelTV);

// Create a TextView to house the value of the after-tax income
TextView valueTV = new TextView(this);
valueTV.setId(current);
valueTV.setText(strAuftraege[current][1]);
System.out.println(valueTV.getText().toString());


// valueTV.setTextColor(Color.BLACK);
valueTV.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
tr.addView(valueTV);

// Add the TableRow to the TableLayout
tl.addView(tr, new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
}


Where is my error?

Answer Source

Perhaps you need to use TableRow.LayoutParams when adding the TextViews to the table row? You are currently using plain old LayoutParams.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download