title: Use same fragment in ViewPager but fragment will have different layout each time
body: <p>I want to keep my application thin.</p>
  
  <p><strong>Problem:</strong> I would like to reuse my <code>Fragment</code> class code to create 3 different instances in the <code>ViewPager</code> which will have 3 pages. Each <code>Fragment</code> will have a different <code>ImageView</code> or background <code>Drawable</code>. What are best practices regarding this? I noticed that using factory methods like <a href="https://stackoverflow.com/questions/15744333/viewpager-pages-with-different-layouts-but-same-fragment-class">here</a> seem to be good, any other alternatives?</p>
  
  <p>I have one <code>Fragment</code> which has the following methods:</p>
  
  <p><strong>Fragment.java</strong></p>
  
  <pre><code>public static Fragment newInstance(Context context) {
      FragmentTutorial f = new FragmentTutorial();
      Bundle args = new Bundle();
  
      return f;
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment, null);
      return root;
  }
  </code></pre>
  
  <p>I have a ViewPagerAdapter class which has the following methods:</p>
  
  <p><strong>ViewPagerAdapter.java</strong></p>
  
  <pre><code>public ViewPagerAdapter(Context context, FragmentManager fm) {
      super(fm);
      mContext = context;
  }
  
  @Override
  public Fragment getItem(int position) {
      return new FragmentTutorial().newInstance(mContext);
  }
  
  @Override
  public int getCount() {
      return totalPage;
  }
  </code></pre>