title: ViewPager in DialogFragment - IllegalStateException: Fragment does not have a view
body: <h2>What I want to achieve</h2>
  
  <ul>
  <li>From a <code>FragmentActivity</code> show a dialog when clicking an Action Button in the Action Bar</li>
  <li><code>DialogFragment</code> - A Dialog without title</li>
  <li><code>TabHost</code> - Tabs at the top of the dialog</li>
  <li><code>ViewPager</code> with <code>FragmentPagerAdapter</code> - Swipable, which content is connected to the Tabs</li>
  <li>2-3 Dialog Buttons (different subclasses of the Dialog, different buttons) - Are not supposed to be in one of the <code>ViewPager</code>'s <code>Fragment</code>, meaning the same buttons should remain at the bottom of the Dialog regardless of what <code>Fragment</code> the <code>ViewPager</code> is showing.</li>
  </ul>
  
  <p><br></p>
  
  <h2>The problem</h2>
  
  <pre><code>IllegalStateException: Fragment does not have a view
  </code></pre>
  
  <p><br></p>
  
  <h2>What I have tried/done so far</h2>
  
  <ul>
  <li>Using the <code>android.support.v4</code> package for necessary classes</li>
  <li>Calling <code>getChildFragmentManager()</code> instead of <code>getSupportedFragmentManager()</code></li>
  <li>Implemented what post #10 suggested from this link <strong><a href="https://code.google.com/p/android/issues/detail?id=42601" rel="noreferrer">https://code.google.com/p/android/issues/detail?id=42601</a></strong>. I copy/paste the code directly into my two <code>Fragment</code> classes, which the <code>ViewPager</code> is suppose to be showing, plus the <code>DialogFragment</code> class.</li>
  <li>In my custom <code>DialogFragment</code> I first tried to override <code>onCreateView</code>, then <code>onCreateDialog</code> and then both at the same time. All of which I got to run but with unexpected results.
  
  <ul>
  <li>Only <code>onCreateView</code>: Can't reach the <code>AlertDialog.Builder</code> to create the needed buttons, other than that the Dialog's results were great.</li>
  <li>Only <code>onCreateDialog</code>: the error message shown above. I still imagine this method to be as close as I've gotten to what I want to achieve.</li>
  <li>Both <code>onCreateView</code> and <code>onCreateDialog</code>: Inflated the Dialog layout in <code>onCreateView</code> and added the Dialog buttons to the <code>AlertDialog.Builder</code> in <code>onCreateDialog</code>. This displayed the dialog, but the added buttons from the <code>AlertDialog.Builder</code> were not visable. Plus the keyboard didn't show up when clicking on a <code>EditText</code> field.</li>
  </ul></li>
  </ul>
  
  <p><br></p>
  
  <h2>Source code</h2>
  
  <p>Most come from <strong><a href="https://stackoverflow.com/questions/17687717/tutorial-to-implement-the-use-of-tabhost-in-android-2-2-viewpager-and-fragment">Tutorial to implement the use of TabHost in Android 2.2 + ViewPager and Fragments</a></strong>. The code of the <code>ActivityFragment</code> is instead in a <code>DialogFragment</code>. However I replaced its ViewPager with a modified one from the source code from this answer <strong><a href="https://stackoverflow.com/a/18167273/2375978">https://stackoverflow.com/a/18167273/2375978</a></strong>. This was to be able to <code>wrap_content</code> on height.</p>
  
  <p>The faulty code in my project is in <code>DialogFragment</code>'s <code>onCreateDialog</code> method, I believe.</p>
  
  <pre><code>@Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {
      AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), AlertDialog.THEME_HOLO_DARK);
      LayoutInflater inflater = getActivity().getLayoutInflater();
      view = inflater.inflate(R.layout.dialog_test, null);
      addActionButtons(builder, view);    
      builder.setView(view);
  
      mViewPager = (WrapContentHeightViewPager) view.findViewById(R.id.viewpager);
  
      initialiseTabHost();
  
      List&lt;Fragment&gt; fragments = getFragments();
  
      pageAdapter = new DialogPageAdapter(getChildFragmentManager(), fragments);
      mViewPager.setAdapter(pageAdapter);
      mViewPager.setOnPageChangeListener(this);
  
      Dialog dialog = builder.create();
      dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
      dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
      dialog.show();
  
      return dialog;
  }
  </code></pre>
  
  <p><br></p>
  
  <h2>Stack trace LogCat log</h2>
  
  <pre><code>FATAL EXCEPTION: main
  java.lang.IllegalStateException: Fragment does not have a view
      at android.support.v4.app.Fragment$1.findViewById(Fragment.java:1425)
      at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:901)
      at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
      at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
      at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)
      at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:461)
      at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
      at android.support.v4.view.ViewPager.populate(ViewPager.java:1011)
      at android.support.v4.view.ViewPager.populate(ViewPager.java:880)
      at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1374)
      at my.app.package.name.WrapContentHeightViewPager.onMeasure(WrapContentHeightViewPager.java:31)
      at android.view.View.measure(View.java:15481)
      at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5059)
      at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1396)
      at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
      at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
      at android.view.View.measure(View.java:15481)
      at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5059)
      at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
      at android.view.View.measure(View.java:15481)
      at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:617)
      at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:399)
      at android.view.View.measure(View.java:15481)
      at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5059)
      at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
      at android.view.View.measure(View.java:15481)
      at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5059)
      at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
      at android.view.View.measure(View.java:15481)
      at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5059)
      at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1396)
      at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
      at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
      at android.view.View.measure(View.java:15481)
      at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5059)
      at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
      at android.view.View.measure(View.java:15481)
      at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5059)
      at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
      at android.view.View.measure(View.java:15481)
      at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5059)
      at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
      at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2377)
      at android.view.View.measure(View.java:15481)
      at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1982)
      at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1200)
      at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1398)
      at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1118)
      at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4525)
      at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
      at android.view.Choreographer.doCallbacks(Choreographer.java:555)
      at android.view.Choreographer.doFrame(Choreographer.java:525)
      at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
      at android.os.Handler.handleCallback(Handler.java:615)
      at android.os.Handler.dispatchMessage(Handler.java:92)
      at android.os.Looper.loop(Looper.java:137)
      at android.app.ActivityThread.main(ActivityThread.java:4946)
      at java.lang.reflect.Method.invokeNative(Native Method)
      at java.lang.reflect.Method.invoke(Method.jav
  </code></pre>
  
  <p><br></p>
  
  <h2>Also...</h2>
  
  <ul>
  <li>I have unsuccessfully been able to try the other possible solution mentioned in <a href="https://code.google.com/p/android/issues/detail?id=42601" rel="noreferrer">https://code.google.com/p/android/issues/detail?id=42601</a>, mentioned in post #2 and #13, because I haven't understood how and where I can use it in my code (I guess I'm in the same boat as the person who wrote #18).</li>
  </ul>