Reputation: 861
I have a dynamic table that I'm trying to make show up on the screen. It's created from parsing an xml string that is returned from a web service. However, it runs through the code with no errors but it's just not adding any rows to the table for me...
public void createTable(String xmlForTable)
throws XmlPullParserException, IOException {
Integer i = 0;
endPlacementTag = "nothing";
lo = (TableLayout) findViewById(R.id.tiresTable);
TableRow headerRow = new TableRow(this);
TableRow.LayoutParams hp = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT);
headerRow.setLayoutParams(hp);
tv = new TextView(this);
tv.setText("Text Header");
headerRow.addView(tv);
lo.addView(headerRow);
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser xpp = factory.newPullParser();
xpp.setInput(new StringReader (xmlForTable));
int eventType = xpp.getEventType();
TableRow row= new TableRow(this);
TableRow.LayoutParams lp = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT);
row.setLayoutParams(lp);
rfid = new TextView(this);
projectNumber = new TextView(this);
inspectionLotNumber = new TextView(this);
serialization = new TextView(this);
spec = new TextView(this);
sku = new TextView(this);
materialNumber = new TextView(this);
while (eventType != XmlPullParser.END_DOCUMENT) {
if(eventType == XmlPullParser.START_DOCUMENT) {
System.out.println("Start document");
} else if(eventType == XmlPullParser.END_DOCUMENT) {
System.out.println("End document");
} else if(eventType == XmlPullParser.START_TAG) {
System.out.println("Start tag "+xpp.getName());
placementTag = xpp.getName();
} else if(eventType == XmlPullParser.END_TAG) {
System.out.println("End tag "+xpp.getName());
endPlacementTag = "End tag "+xpp.getName();
} else if(eventType == XmlPullParser.TEXT) {
System.out.println("Text "+xpp.getText());
//If the text tag is equal to "Table" do nothing otherwise...
if(placementTag.equals("Table"))
{
//Do Nothing
}
else if(placementTag.equals("Serialization"))
{
serialization.setText(xpp.getText());
serialization.setTextSize(10);
serialization.setLayoutParams(new LayoutParams (LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
//row.addView(serialization);
placementTag = "";
}
... //Other if statements
else if(endPlacementTag.equals("End tag Table"))
{
row.addView(rfid);
row.addView(projectNumber);
row.addView(inspectionLotNumber);
row.addView(serialization);
row.addView(spec);
row.addView(sku);
row.addView(materialNumber);
row.setGravity(Gravity.CENTER);
row.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT));
lo.addView(row, new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT));
//i++;
row.removeAllViews();
lo.removeAllViews();
}
}
eventType = xpp.next();
}
I have set the params like I have read in other examples on SO, and I made sure that I had the import android.widget.TableRow.LayoutParams;
imported rather than import android.view.ViewGroup.LayoutParams;
Anyone have any ideas?
Upvotes: 0
Views: 116
Reputation: 4673
TableRow.LayoutParams lp = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT);
I think the above constructor is not what you are looking for. The above is
public TableRow.LayoutParams (int column)
Puts the view in the specified column.
Sets the child width to MATCH_PARENT and the child height to WRAP_CONTENT.
You probably wanted to use this one:
public TableRow.LayoutParams (int w, int h)
Sets the child width and height.
Like this:
TableRow.LayoutParams lp = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,TableRow.LayoutParams.WRAP_CONTENT);
Upvotes: 1