title: Android Dialog error The specified child already has a parent. You must call removeView() on the child's parent first
body: <p>I am trying to give data to my listView, When clicking FAB then it shows a dialog box with one editText and two buttons. In first time it allow me to give data to ListView. but when I try second time it shows the error:</p>
  
  <blockquote>
    <p>FATAL EXCEPTION: main <br>
    Process: com.example.app.wounderlist.wounderlist, PID: 3790 <br>
                                                                                           java.lang.IllegalStateException: <strong>The</strong> <strong>specified</strong> <strong>child</strong> <strong>already</strong> <strong>has</strong> <strong>a</strong> <strong>parent</strong>. <strong>You</strong> <strong>must</strong> <strong>call</strong> <strong>removeView()</strong> <strong>on</strong> <strong>the</strong> <strong>child's</strong> <strong>parent</strong> <strong>first.</strong>
                                                                                               at android.view.ViewGroup.addViewInner(ViewGroup.java:3562)
                                                                                               at android.view.ViewGroup.addView(ViewGroup.java:3415)
                                                                                               at android.view.ViewGroup.addView(ViewGroup.java:3391)
                                                                                               at android.support.v7.app.AlertController.setupCustomContent(AlertController.java:647)
                                                                                               at android.support.v7.app.AlertController.setupView(AlertController.java:463)
                                                                                               at android.support.v7.app.AlertController.installContent(AlertController.java:226)
                                                                                               at android.support.v7.app.AlertDialog.onCreate(AlertDialog.java:257)
                                                                                               at android.app.Dialog.dispatchOnCreate(Dialog.java:361)
                                                                                               at android.app.Dialog.show(Dialog.java:262)
                                                                                               at com.example.app.wounderlist.wounderlist.HomeFragment$1.onClick(HomeFragment.java:79)
                                                                                               at android.view.View.performClick(View.java:4444)
                                                                                               at android.view.View$PerformClick.run(View.java:18457)
                                                                                               at android.os.Handler.handleCallback(Handler.java:733)
                                                                                               at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                               at android.os.Looper.loop(Looper.java:136)
                                                                                               at android.app.ActivityThread.main(ActivityThread.java:5113)
                                                                                               at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                               at java.lang.reflect.Method.invoke(Method.java:515)
                                                                                               at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
                                                                                               at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
                                                                                               at dalvik.system.NativeStart.main(Native Method)</p>
  </blockquote>
  
  <h1>And here is my code</h1>
  
  <pre><code>//create a dialog box with a editText and a Add button when pressing the #FAB
          final EditText taskEditText = new EditText(getActivity());
          mFab.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  AlertDialog dialog = new AlertDialog.Builder(getActivity())
                          .setTitle("Add a new task")
                          .setMessage("What do you want to do next?")
                          .setView(taskEditText)
                          .setPositiveButton("Add", new DialogInterface.OnClickListener() {
                              @Override
                              public void onClick(DialogInterface dialog, int which) {
  
                                  //for getting text from the editText
                                  String itemText = taskEditText.getText().toString();
                                  mItemsAdapter.add(itemText);
  
  
                              }
                          })
                          .setNegativeButton("Cancel", null)
                          .create();
                  dialog.show();
              }
          });
  </code></pre>