Fix monkey crash in RawContactEditorView

Bug: 8011818
Change-Id: I3c69f253aadfc94ee4bc7364d2943b9068efd394
diff --git a/src/com/android/contacts/editor/RawContactEditorView.java b/src/com/android/contacts/editor/RawContactEditorView.java
index 9099307..b52b0b2 100644
--- a/src/com/android/contacts/editor/RawContactEditorView.java
+++ b/src/com/android/contacts/editor/RawContactEditorView.java
@@ -73,6 +73,7 @@
 
     private ViewGroup mOrganizationSectionViewContainer;
     private View mAddOrganizationButton;
+    private View mOrganizationView;
     private boolean mOrganizationViewExpanded = false;
 
     private ViewGroup mFields;
@@ -148,6 +149,13 @@
         mAccountTypeTextView = (TextView) findViewById(R.id.account_type);
         mAccountNameTextView = (TextView) findViewById(R.id.account_name);
 
+        mOrganizationView = mInflater.inflate(
+                R.layout.organization_editor_view_switcher, mFields, false);
+        mAddOrganizationButton = mOrganizationView.findViewById(
+                R.id.add_organization_button);
+        mOrganizationSectionViewContainer =
+                (ViewGroup) mOrganizationView.findViewById(R.id.container);
+
         mAddFieldButton = (Button) findViewById(R.id.button_add_field);
         mAddFieldButton.setOnClickListener(new OnClickListener() {
             @Override
@@ -300,12 +308,7 @@
                 } else {
                     // Otherwise provide the user with an "add organization" button that shows the
                     // EditText fields only when clicked
-                    final View organizationView = mInflater.inflate(
-                            R.layout.organization_editor_view_switcher, mFields, false);
-                    mAddOrganizationButton = organizationView.findViewById(
-                            R.id.add_organization_button);
-                    mOrganizationSectionViewContainer =
-                            (ViewGroup) organizationView.findViewById(R.id.container);
+                    mOrganizationSectionViewContainer.removeAllViews();
                     mOrganizationSectionViewContainer.addView(section);
 
                     // Setup the click listener for the "add organization" button
@@ -320,7 +323,7 @@
                         }
                     });
 
-                    mFields.addView(organizationView);
+                    mFields.addView(mOrganizationView);
                 }
             } else {
                 // Otherwise use generic section-based editors