title: BadTokenException when populating Spinner inside Fragment
body: <p>Why can't I populate Spinner's dialog inside Fragment in Support package?</p>
  
  <p>Due to the requirement in UI design, I ended up having subview inside Fragment. So the structure is like:
  Activity -> Fragment -> (ProfileView, ContactsView) both extends FrameLayout</p>
  
  <p>Everything looks and works fine except Spinner.</p>
  
  <p>Inside ProfileView I have this constructor that I use to create the view. In the mean time I took both Context and Fragment, just in case. </p>
  
  <pre><code>public ProfileView(Context context, Fragment parent) {
      super(context);
      this.context = context;
      this.parent = parent;
  }
  </code></pre>
  
  <p>And when initializing the view I have</p>
  
  <pre><code>List&lt;LanguageVO&gt; languageList = XMLResourceManager.GetLanguagesList(this.context.getResources()); // Load resource from XML     
  spnLanguage = (Spinner) view.findViewById(R.id.spnLanguage);
      ArrayAdapter&lt;CharSequence&gt; adapter = new ArrayAdapter(this.parent.getSupportActivity().getApplicationContext(), android.R.layout.simple_spinner_item, languageList);
      adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
      spnLanguage.setAdapter(adapter);
  </code></pre>
  
  <p>I tried passing all these into Adapter for Context but none of them works. All causes BadTokenException (except the two those are NULL to begin with).</p>
  
  <pre><code>this.context
  this.parent
  this.parent.getActivity()
  this.parent.getActivity().getParent() // NULL
  this.parent.getSupportActivity()
  this.parent.getSupportActivity().getParent() // NULL
  parent.getSupportActivity().getApplicationContext()
  </code></pre>
  
  <p>The screen works out fine, I can even load XML from context resources. So why the Spinner does not work?</p>
  
  <p>I should add that the stack trace below is from running on 2.2/2.3 devices. The code works fine on ICS.</p>
  
  <p>Stack trace:</p>
  
  <pre><code>02-29 03:18:35.675: E/AndroidRuntime(4165): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
  02-29 03:18:35.675: E/AndroidRuntime(4165):     at android.view.ViewRoot.setView(ViewRoot.java:539)
  02-29 03:18:35.675: E/AndroidRuntime(4165):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:203)
  02-29 03:18:35.675: E/AndroidRuntime(4165):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:117)
  02-29 03:18:35.675: E/AndroidRuntime(4165):     at android.app.Dialog.show(Dialog.java:241)
  02-29 03:18:35.675: E/AndroidRuntime(4165):     at android.app.AlertDialog$Builder.show(AlertDialog.java:802)
  02-29 03:18:35.675: E/AndroidRuntime(4165):     at android.widget.Spinner.performClick(Spinner.java:261)
  02-29 03:18:35.675: E/AndroidRuntime(4165):     at android.view.View$PerformClick.run(View.java:9152)
  02-29 03:18:35.675: E/AndroidRuntime(4165):     at android.os.Handler.handleCallback(Handler.java:587)
  02-29 03:18:35.675: E/AndroidRuntime(4165):     at android.os.Handler.dispatchMessage(Handler.java:92)
  02-29 03:18:35.675: E/AndroidRuntime(4165):     at android.os.Looper.loop(Looper.java:123)
  02-29 03:18:35.675: E/AndroidRuntime(4165):     at android.app.ActivityThread.main(ActivityThread.java:3691)
  02-29 03:18:35.675: E/AndroidRuntime(4165):     at java.lang.reflect.Method.invokeNative(Native Method)
  02-29 03:18:35.675: E/AndroidRuntime(4165):     at java.lang.reflect.Method.invoke(Method.java:507)
  02-29 03:18:35.675: E/AndroidRuntime(4165):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
  02-29 03:18:35.675: E/AndroidRuntime(4165):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
  02-29 03:18:35.675: E/AndroidRuntime(4165):     at dalvik.system.NativeStart.main(Native Method)
  </code></pre>