how to access UI elements in parent activity from fragment
<p>parent activity layout</p>

<pre><code>&lt;RelativeLayout 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=".LockerCodeActivity" &gt;

    &lt;LinearLayout
        android:id="@+id/fragment_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"&gt;
    &lt;/LinearLayout&gt;

    &lt;ProgressBar
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:id="@+id/ctrlActivityIndicator"
        android:indeterminateOnly="true"
        android:keepScreenOn="false"
     /&gt;

    &lt;TextView
        android:id="@+id/tv_results"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="" /&gt;

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

<p>Inflate the fragment in the parent activity onCreate function</p>

<pre><code>FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    Fragment scannerFragment = new ScanFragment();
    fragmentTransaction.add(R.id.fragment_container, scannerFragment);
    fragmentTransaction.commit();
</code></pre>

<p>Working great so far... now how do I hide the progressbar?
This is what I've tried</p>

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

    ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.ctrlActivityIndicator);
    progressBar.setVisibility(View.INVISIBLE);
    return view;
    }
</code></pre>

<p>I get a null pointer exception</p>
