Merge "Replace auto-create in findViewById() with explicit create() API"
diff --git a/api/current.txt b/api/current.txt
index 82eabc7..5642b15 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -3393,6 +3393,7 @@
method public void addContentView(android.view.View, android.view.ViewGroup.LayoutParams);
method public void cancel();
method public void closeOptionsMenu();
+ method public void create();
method public void dismiss();
method public boolean dispatchGenericMotionEvent(android.view.MotionEvent);
method public boolean dispatchKeyEvent(android.view.KeyEvent);
diff --git a/core/java/android/app/AlertDialog.java b/core/java/android/app/AlertDialog.java
index b963ff2..ab148a9 100644
--- a/core/java/android/app/AlertDialog.java
+++ b/core/java/android/app/AlertDialog.java
@@ -147,12 +147,8 @@
/**
* Gets one of the buttons used in the dialog. Returns null if the specified
- * button does not exist in the dialog.
- * <p>
- * Prior to API 20, this function could only be called after the dialog was
- * shown. In later versions, this function may be called at any time;
- * however, calling this function locks in various attributes including
- * buttons and icons.
+ * button does not exist or the dialog has not yet been fully created (for
+ * example, via {@link #show()} or {@link #create()}).
*
* @param whichButton The identifier of the button that should be returned.
* For example, this can be
@@ -160,8 +156,6 @@
* @return The button from the dialog, or null if a button does not exist.
*/
public Button getButton(int whichButton) {
- // Superclass handles re-entrance and multiple calls.
- dispatchOnCreate(null);
return mAlert.getButton(whichButton);
}
diff --git a/core/java/android/app/Dialog.java b/core/java/android/app/Dialog.java
index 17903ea..2559254 100644
--- a/core/java/android/app/Dialog.java
+++ b/core/java/android/app/Dialog.java
@@ -105,9 +105,6 @@
private boolean mShowing = false;
private boolean mCanceled = false;
- /** Whether the execution path is currently in onCreate(). */
- private boolean mInOnCreate = false;
-
private final Handler mHandler = new Handler();
private static final int DISMISS = 0x43;
@@ -242,6 +239,18 @@
}
/**
+ * Forces immediate creation of the dialog.
+ * <p>
+ * Note that you should not override this method to perform dialog creation.
+ * Rather, override {@link #onCreate(Bundle)}.
+ */
+ public void create() {
+ if (!mCreated) {
+ dispatchOnCreate(null);
+ }
+ }
+
+ /**
* Start the dialog and display it on screen. The window is placed in the
* application layer and opaque. Note that you should not override this
* method to do initialization when the dialog is shown, instead implement
@@ -359,10 +368,8 @@
// internal method to make sure mcreated is set properly without requiring
// users to call through to super in onCreate
void dispatchOnCreate(Bundle savedInstanceState) {
- if (!mCreated && !mInOnCreate) {
- mInOnCreate = true;
+ if (!mCreated) {
onCreate(savedInstanceState);
- mInOnCreate = false;
mCreated = true;
}
}
@@ -461,20 +468,14 @@
}
/**
- * Finds a child view with the given identifier.
- * <p>
- * Prior to API 20, this function could only be used after the first call
- * to {@link #show()}. In later versions, this function may be used at any
- * time; however, the first call to this function "locks in" certain dialog
- * characteristics.
+ * Finds a child view with the given identifier. Returns null if the
+ * specified child view does not exist or the dialog has not yet been fully
+ * created (for example, via {@link #show()} or {@link #create()}).
*
* @param id the identifier of the view to find
* @return The view with the given id or null.
*/
public View findViewById(int id) {
- if (!mCreated) {
- dispatchOnCreate(null);
- }
return mWindow.findViewById(id);
}