title: You must call removeview on the child parent first. Android
body: <p>I got a problem with opening spinner. When i open it first time it opens correctly and lets me choose from it. Then when i try to open it second time it gives me an error:</p>
  
  <pre><code>11-21 18:43:49.589: E/AndroidRuntime(3178): java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
  </code></pre>
  
  <p>My spinner opens on click on ImageButton. Here the code:</p>
  
  <pre><code>    final ArrayAdapter&lt;String&gt; adp = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_spinner_item, s);
      final Spinner sp = new Spinner(this);
      final AlertDialog.Builder builder = new AlertDialog.Builder(this);
      ImageButton bracket = (ImageButton) findViewById(R.id.imageButton1);
      bracket.setOnClickListener(new OnClickListener() {
          public void onClick(View arg0) {
              sp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                  public void onItemSelected(AdapterView&lt;?&gt; adapterView, View view, int i, long l) {
                      choosed_bracket = (String) sp.getItemAtPosition(i);
                  }
  
                  public void onNothingSelected(AdapterView&lt;?&gt; adapterView) {
                      return;
                  }
              });
              sp.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
              sp.setAdapter(adp);
  
              builder.setTitle("Choose war bracket:");
              builder.setView(sp);
              builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int which) {
                      /*SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
                      SharedPreferences.Editor editor = settings.edit();
                      editor.putString("bracket", choosed_bracket);
                      editor.commit(); */
                      Toast.makeText(getApplicationContext(), "Choosed bracket is: " + choosed_bracket, Toast.LENGTH_LONG).show();
                  }
              });
              builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int which) {
                      dialog.cancel();
                  }
              });
              builder.create().show();
          }
      });
  </code></pre>
  
  <p>Hope you can help me!</p>