Fix a crash if the app is restarted while the edit bookmarks folder database view...
[PrivacyBrowser.git] / app / src / main / java / com / stoutner / privacybrowser / dialogs / EditBookmarkFolderDatabaseViewDialog.kt
index e15e29ef6eba698e4a767abd3233bbce90755912..ba538f59db319072c2837bcc952f08dd5a51bbd4 100644 (file)
@@ -349,15 +349,18 @@ class EditBookmarkFolderDatabaseViewDialog : DialogFragment() {
             }
         })
 
-        // Update the save button if the parent folder changes.
-        parentFolderSpinner.onItemSelectedListener = object: OnItemSelectedListener {
-            override fun onItemSelected(parent: AdapterView<*>?, view: View, position: Int, id: Long) {
-                // Update the save button.
-                updateSaveButton(bookmarksDatabaseHelper, currentFolderName, currentParentFolderDatabaseId, currentDisplayOrder)
-            }
+        // Wait to set the on item selected listener until the spinner has been inflated.  Otherwise the dialog will crash on restart.
+        parentFolderSpinner.post {
+            // Update the save button if the parent folder changes.
+            parentFolderSpinner.onItemSelectedListener = object: OnItemSelectedListener {
+                override fun onItemSelected(parent: AdapterView<*>, view: View, position: Int, id: Long) {
+                    // Update the save button.
+                    updateSaveButton(bookmarksDatabaseHelper, currentFolderName, currentParentFolderDatabaseId, currentDisplayOrder)
+                }
 
-            override fun onNothingSelected(parent: AdapterView<*>?) {
-                // Do nothing.
+                override fun onNothingSelected(parent: AdapterView<*>) {
+                    // Do nothing.
+                }
             }
         }