Add a ProgressBar programatically to a Fragment in Android
<p>I was able to manipulate some text of an existing TextView in a Fragment. However I was not able to programatically add a new <code>ProgressBar</code> to the existing layout.<br>
In the Fragment class:  </p>

<pre><code> @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_completed_office_hours, container, false);

        LinearLayout linearLayout = (LinearLayout) view.findViewById(R.id.linearLayoutCompletedOfficeHours);

        progressBar = new ProgressBar(this.getContext());
        progressBar.setMax(daysInTotal);
        progressBar.setProgress(daysCompleted);

        linearLayout.addView(progressBar);

        TextView textView = (TextView) view.findViewById(R.id.completedXOfYDays);
        textView.setText(daysCompleted + " / " + daysInTotal);
        return view;
    }
</code></pre>

<p>The xml:</p>

<pre><code>&lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".fragment.CompletedOfficeHoursFragment"&gt;

    &lt;LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="@dimen/activity_horizontal_margin"
        android:orientation="horizontal"
        android:id="@+id/linearLayoutCompletedOfficeHours"&gt;
        &lt;TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/completedXOfYDays" /&gt;
    &lt;/LinearLayout&gt;
&lt;/FrameLayout&gt;
</code></pre>

<p>When executing it I get <code>19 / 299</code> as text, but without any <code>ProgressBar</code>. What am I doing wrong=</p>