Question

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?

Was it helpful?

Solution

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

OTHER TIPS

Use

tr.addview(tv1,new TableRow.LayoutParam(
      android.widget.TableLayout.LayoutParam.FILLPARENT,
      android.widget.TableLayout.LayoutParam.WILLPARENT) 

in place of

tr.addview(tv1,new LayoutParam(
      Layoutparam.FILLPARENT,
      LayoutParam.WRAPPARENT);

It will resolve your problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top