Adding TableRows Dynamically to A Fragment
<p>I'm trying to add some random data to my dynamically created TableLayout just to see if it's working.</p>

<p>Here is the code</p>

<pre><code>import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TableRow.LayoutParams;
import android.widget.TextView;

public class BasicDetailsTabFragment extends Fragment
{
    int numvals = 5;
    public static final int NAME = 0;
    public static final int BRANCH = 1;
    public static final int EMAIL = 2;
    public static final int REGISTRATION = 3;
    public static final int ADMISSION = 4;

    String[] details = new String[5];
    String[] detailVals = new String[5]; // Get the values from JSON here

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        if (container == null)
        {
            return null;
        }

        details[NAME] = "Name";
        details[BRANCH] = "Branch";
        details[EMAIL] = "Email";
        details[REGISTRATION] = "Registration No.";
        details[ADMISSION] = "Admission No. ";

        detailVals[NAME] = "Some Name";
        detailVals[BRANCH] = "Computer Science";
        detailVals[EMAIL] = "some_email@email.com";
        detailVals[REGISTRATION] = "11101212";
        detailVals[ADMISSION] = "1345645";

         View view = inflater.inflate(R.layout.basic_details_layout,
         container, false);

        TableLayout tl = (TableLayout)view.getView().findViewById(R.id.detailsTable);

        for (int i = 0; i &lt; numvals; i++)
        {
            // Make TR
            TableRow tr = new TableRow(getActivity());
            tr.setId(100 + i);
            tr.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

            // Make TV to hold the details
            TextView detailstv = new TextView(getActivity());
            detailstv.setId(200 + i);
            detailstv.setText(details[i]);
            tr.addView(detailstv);

            // Make TV to hold the detailvals

            TextView valstv = new TextView(getActivity());
            valstv.setId(300 + i);
            valstv.setText(detailVals[i]);
            tr.addView(valstv);

            tl.addView(tr, new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        }

        return (RelativeLayout) inflater.inflate(R.layout.basic_details_layout, container, false);

    }
</code></pre>

<p>And here is the xml of layout for this class</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" &gt;

    &lt;ImageView
        android:id="@+id/studentPhoto"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="15dp"
        android:src="@drawable/student_photo" /&gt;

    &lt;TableLayout
        android:id="@+id/detailsTable"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/studentPhoto" &gt;
    &lt;/TableLayout&gt;

&lt;/RelativeLayout&gt;
</code></pre>

<p>This approach however doesn't work(Nothing is displayed except the photo)
I'm a relative beginner in using Fragments and what I'm also confused is among which functions (onCreate(),onCreateActivity() etc ) im supposed to put the above code so it populates my Table.</p>

<p>Any help is appreciated.</p>

<p>I apologize in advance if my question seems overly stupid. </p>
