title: How do I find the ID of a fragment? Alternatively, how do I give the fragment an ID?
body: <p>(First, I'm aware this question has been asked plenty of times, but I haven't found an applicable answer)</p>
  
  <p>I have a fragment created as such:</p>
  
  <pre><code>inflater.inflate ( R.layout.fragment_task_ongoing, container, false );
  </code></pre>
  
  <p>What I'd like, is to use findFragmentById in the FragmentActivity, like this:</p>
  
  <pre><code>TaskActiveFragment f = ( TaskActiveFragment ) getSupportFragmentManager ().findFragmentById ( R.id.fragment_task_ongoing );
  </code></pre>
  
  <p>Unfortunately, this returns null. The apparent reason is that the id used as a parameter, is the id of the RelativeLayout being inflated, and not the Fragment. First lines of the layout:</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/fragment_task_ongoing"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:paddingLeft="16dp"
  android:paddingRight="16dp" &gt;
  </code></pre>
  
  <p>So, how do I find out what ID the <em>fragment</em> has? If it doesn't have an ID, how do I give it one? Programatically? XML?</p>
  
  <p>Edit: My fragments are added to a FragmentStatePagerAdapter, which is then added to a ViewPager.</p>