title: Share a fragment with several classes?
body: <p>I wonder how I can best create a progress bar fragment. It must be usable by every other class of course.</p>
  
  <p>At the moment I have just a ProgressBarFragment, which has public setVisible method. Getting the Fragment through FragmentManager I can set it visible or not. But is this the right way to do these sort of actions?</p>
  
  <pre><code>public class MyActivity exetends FragmentActivity {
      void setVisibility(int visible) {
          ProgressBarFragment fragment = (ProgressBarFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_progress_bar);
          fragment.setProgressBar(visible);
      }
  }
  </code></pre>
  
  <p>And of course I have several other Fragments which uses this code too, to trigger the progress bar.</p>
  
  <pre><code>public class ProgressBarFragment extends Fragment {
      public void setProgressBar(int visible) {
          progressBar = (ProgressBar) getActivity().findViewById(R.id.progress_bar);
          progressBar.setVisibility(visible);
      }
  }
  </code></pre>