1

Hi i would like to get a table layout to fill with the data of a XML when the activity first starts but im kind of a newbie so i really have no idea on how to do it if someone know how could i possibly do this

1 Answer 1

3

You can add table row dynamically as

for(int i=0;i<youxmlArray.size();i++){
    // get a reference for the TableLayout
    TableLayout table = (TableLayout)findViewById(R.id.TableLayout01);
    // create a new TableRow
    TableRow row = new TableRow(this);
    // create a new TextView for showing xml data
    TextView t = new TextView(this);
    // set the text to "text xx"
    t.setText( "YOUR XML DATA  HERE");
    // add the TextView  to the new TableRow
    row.addView(t);
    // add the TableRow to the TableLayout
    table.addView(row, new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); 
}

and Add a TableLayout in your xml layout as

<TableLayout 
android:id = "@+id/TableLayout01" 
android:layout_width = "fill_parent" 
android:layout_height = "wrap_content"   
android:stretchColumns = "0" >
   < TableRow android:id = "@+id/TableRow01" 
   android:layout_width = "wrap_content" 
   android:layout_height = "wrap_content" >
      < TextView android:id = "@+id/TextView01" 
        android:layout_width = "fill_parent" 
        android:layout_height = "wrap_content" 
        android:text = "textfield 1-1" >
        </ TextView >
   </ TableRow >
</ TableLayout > 
Sign up to request clarification or add additional context in comments.

2 Comments

will it go through all the XML data until it reaches the last entry?
try it if u have any problem then post your code i will edit it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.