From c0491ed1952633103732ae90bb26cf533304bcc3 Mon Sep 17 00:00:00 2001 From: Makoto Onuki Date: Mon, 9 May 2011 11:56:17 -0700 Subject: [PATCH] Add UiUtilities.getViewOrNull() They're variants of getView() that will *not* crash even if the view doesn't exist. I didn't add them before as they would be exactly same as findViewbyId(), but now that we make use of generics they'll be handy. Change-Id: Ib649e591a987183064c7e98afe0e2414d9e62280 --- src/com/android/email/activity/UiUtilities.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/com/android/email/activity/UiUtilities.java b/src/com/android/email/activity/UiUtilities.java index f55878b2f..d4531ab8b 100644 --- a/src/com/android/email/activity/UiUtilities.java +++ b/src/com/android/email/activity/UiUtilities.java @@ -66,6 +66,18 @@ public class UiUtilities { } } + /** Generics version of {@link Activity#findViewById} */ + @SuppressWarnings("unchecked") + public static T getViewOrNull(Activity parent, int viewId) { + return (T) parent.findViewById(viewId); + } + + /** Generics version of {@link View#findViewById} */ + @SuppressWarnings("unchecked") + public static T getViewOrNull(View parent, int viewId) { + return (T) parent.findViewById(viewId); + } + /** * Same as {@link Activity#findViewById}, but crashes if there's no view. */