Still could not get it working. To simplify the debugging, I have written some test code (downloaded it from a forum actually:)). I wonder why even this does not work. public class TestTableLayout extends Activity {
int PROVINCE_Alberta = 0; int PROVINCE_BC = 1; int PROVINCE_Manitoba = 2; int PROVINCE_NewBrunswick = 3; int PROVINCE_Newfoundland = 4; int PROVINCE_Northwest = 5; int PROVINCE_NovaScotia = 6; int PROVINCE_Nunavut = 7; int PROVINCE_Ontario = 8; int PROVINCE_PEI = 9; int PROVINCE_Quebec = 10; int PROVINCE_Saskatchewan = 11; int PROVINCE_Yukon = 12; int numProvinces = 13; String[] provinces = new String[numProvinces]; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); provinces[PROVINCE_Alberta] = "Alberta"; provinces[PROVINCE_BC] = "British Columbia"; provinces[PROVINCE_Manitoba] = "Manitoba"; provinces[PROVINCE_NewBrunswick] = "New Brunswick"; provinces[PROVINCE_Newfoundland] = "Newfoundland and Labrador"; provinces[PROVINCE_Northwest] = "Northwest Territories"; provinces[PROVINCE_NovaScotia] = "Nova Scotia"; provinces[PROVINCE_Nunavut] = "Nunavut"; provinces[PROVINCE_Ontario] = "Ontario"; provinces[PROVINCE_PEI] = "Prince Edward Island"; provinces[PROVINCE_Quebec] = "Quebec"; provinces[PROVINCE_Saskatchewan] = "Saskatchewan"; provinces[PROVINCE_Yukon] = "Yukon"; // Get the TableLayout TableLayout tl = (TableLayout) findViewById(R.id.maintable); // Go through each item in the array for (int current = 0; current < numProvinces; 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(provinces[current]); 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("$0"); 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)); } tl.invalidate(); } } <?xml version="1.0" encoding="utf-8"?> <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> Please help Siddharth On Jan 20, 10:51 pm, Conny <mcon...@gmail.com> wrote: > Walt, > > Thanks a lot for your responses. Very useful. > > Trying out what you suggested. One interesting find, hierarchyViewer > reports getHeight and getWeight = 0 for the view objects in the row. I > also identified a classcastexception, my worst exception so far (gives > no hint where the problem originates) > > Had not used (ViewGroup.LayoutParams) new LinearLayout.LayoutParams > for the LinearLayout > instead used LayoutParams > > Will report back. > > Regards > Siddharth > > On Jan 19, 7:45 pm, Walt Armour <waltarm...@gmail.com> wrote: > > > Well, if hierarchyviewer says it's there, then it's there. > > > When I have problems like this I usually end up finding that a WRAP_CONTENT > > or FILL_PARENT wasn't behaving like I thought it should. > > > The only suggestions I have would be: > > - Try reordering the addViews at the bottom so that you add everything to > > the linear layout first then to the row. Total shot in the dark. > > - Further troubleshooting: give elements a unique background color (just to > > be able to visually ID them) and then start working through the > > WRAP_CONTENTs to see if perhaps one should be FILL_PARENT. > > > On Mon, Jan 18, 2010 at 21:18, Conny <mcon...@gmail.com> wrote: > > > Thanks, loaded the tool for the first time. Yup, I checked its there. > > > > Any log files I can send paste ? I am not able to attach png files. > > > > Siddharth > > > > On Jan 18, 12:13 am, Walt Armour <waltarm...@gmail.com> wrote: > > > > I can't say for sure just looking at the code. However, you may want to > > > run > > > > the hierarchy viewer tool (part of the SDK in the tools directory) and > > > see > > > > if you can tell where your new row lands in the view hierarchy. > > > > > On Sun, Jan 17, 2010 at 00:54, MCON Dev <mcon...@gmail.com> wrote: > > > > > I have TableLayout defined in the main.xml. Simple, 1 header row and > > > > > 1 > > > > > data row. > > > > > <TableLayout android:id="@+id/*reportsTable*" > > > > > android:layout_width="fill_parent" > > > > > android:layout_height="wrap_content"> > > > > > <TableRow> > > > > > <TextView android:id="@+id/DateOfReport" > > > > > android:text="Report Date" > > > > > android:textSize="14px" > > > > > android:layout_width="wrap_content" > > > > > android:layout_height="wrap_content" /> > > > > > <TextView android:id="@+id/HeightHeading" > > > > > android:text="Height" > > > > > android:textSize="14px" > > > > > android:layout_width="wrap_content" > > > > > android:layout_height="wrap_content" /> > > > > > <TextView android:id="@+id/WeightHeading" > > > > > android:text="Weight" > > > > > android:textSize="14px" > > > > > android:layout_width="wrap_content" > > > > > android:layout_height="wrap_content" /> > > > > > </TableRow> > > > > > <TableRow android:id="@+id/r1" > > > > > android:layout_width="wrap_content" > > > > > android:layout_height="wrap_content"> > > > > > <LinearLayout android:orientation="horizontal" > > > > > android:layout_width="fill_parent" > > > > > android:layout_height="wrap_content"> > > > > > <EditText android:id="@+id/dateOfReport" > > > > > android:text="DD/MM/YYYY" > > > > > android:textSize="11px" > > > > > android:layout_width="wrap_content" > > > > > android:layout_height="wrap_content" > > > > > /> > > > > > <Button android:id="@+id/changeReportDate" > > > > > android:text="..." > > > > > android.textSize="12px" > > > > > android:layout_width="wrap_content" > > > > > android:layout_height="wrap_content" > > > > > /> > > > > > </LinearLayout> > > > > > <EditText android:id="@+id/height" > > > > > android:text="inCmOrInch" > > > > > android:textSize="11px" > > > > > android:layout_width="wrap_content" > > > > > android:layout_height="wrap_content" /> > > > > > <EditText android:id="@+id/weight" > > > > > android:text="inKgOrPound" > > > > > android:textSize="11px" > > > > > android:layout_width="wrap_content" > > > > > android:layout_height="wrap_content" /> > > > > > </TableRow> > > > > > > Now in the code I have a function defined that adds a new row. > > > > > > private TableRow createNewTableRow(TableRow newRow){ > > > > > newRow.setLayoutParams(new > > > > > LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)) ; > > > > > LinearLayout newLinearLayout = new LinearLayout(appActivity) ; > > > > > newLinearLayout.setOrientation(LinearLayout.HORIZONTAL); > > > > > newLinearLayout.setLayoutParams(new > > > > > LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT)) ; > > > > > EditText newReportDate = new EditText(appActivity) ; > > > > > newReportDate.setTextSize((float) 11.0); > > > > > newReportDate.setLayoutParams(new > > > > > LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)) ; > > > > > Button changeReportDate = new Button(appActivity) ; > > > > > changeReportDate.setTextSize((float) 12.0); > > > > > changeReportDate.setLayoutParams(new > > > > > LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)) ; > > > > > changeReportDate.setText("..."); > > > > > EditText newHeight = new EditText(appActivity) ; > > > > > newHeight.setTextSize((float) 11.0); > > > > > newHeight.setLayoutParams(new > > > > > LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)) ; > > > > > EditText newWeight = new EditText(appActivity) ; > > > > > newWeight.setTextSize((float) 11.0); > > > > > newWeight.setLayoutParams(new > > > > > LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)) ; > > > > > > newRow.addView(newLinearLayout); > > > > > newLinearLayout.addView(newReportDate); > > > > > newLinearLayout.addView(changeReportDate); > > > > > newRow.addView(newHeight); > > > > > newRow.addView(newWeight); > > > > > return newRow ; > > > > > } > > > > > > Now, in the main code I call this function > > > > > > if (v == (View) *addReportWidget*) { > > > > > TableRow newRow = new TableRow(appActivity, null); > > > > > *reportsTableWidget*.addView(createNewTableRow(newRow)); > > > > > reportsTab.invalidate(); > > > > > } > > > > > > Now, the new row just wont show up. If I run the code in the debugger, > > > and > > > > > watch *reportsTableWidget*.mChildren, everytime I click on * > > > > > addReportWidget*, a new entry shows up in the debugger watch > > > > > variables. > > > > > > What am I missing. Very frustating, please advice me. > > > > > > Regards > > > > > Siddharth > > > > > > -- > > > > > You received this message because you are subscribed to the Google > > > > > Groups "Android Beginners" group. > > > > > > NEW! Try asking and tagging your question on Stack Overflow at > > > > >http://stackoverflow.com/questions/tagged/android > > > > > > To unsubscribe from this group, send email to > > > > > android-beginners+unsubscr...@googlegroups.com<android-beginners%2bunsubscr...@googlegroups.com> > > > <android-beginners%2bunsubscr...@googlegroups.com<android-beginners%252bunsubscr...@googlegroups.com> > > > > > > For more options, visit this group at > > > > >http://groups.google.com/group/android-beginners?hl=en > > > > -- > > > You received this message because you are subscribed to the Google > > > Groups "Android Beginners" group. > > > > NEW! Try asking and tagging your question on Stack Overflow at > > >http://stackoverflow.com/questions/tagged/android > > > > To unsubscribe from this group, send email to > > > android-beginners+unsubscr...@googlegroups.com<android-beginners%2bunsubscr...@googlegroups.com> > > > For more options, visit this group at > > >http://groups.google.com/group/android-beginners?hl=en -- You received this message because you are subscribed to the Google Groups "Android Beginners" group. NEW! Try asking and tagging your question on Stack Overflow at http://stackoverflow.com/questions/tagged/android To unsubscribe from this group, send email to android-beginners+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en