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
This commit is contained in:
Makoto Onuki 2011-05-09 11:56:17 -07:00
parent c0042a2278
commit c0491ed195

View File

@ -66,6 +66,18 @@ public class UiUtilities {
} }
} }
/** Generics version of {@link Activity#findViewById} */
@SuppressWarnings("unchecked")
public static <T extends View> T getViewOrNull(Activity parent, int viewId) {
return (T) parent.findViewById(viewId);
}
/** Generics version of {@link View#findViewById} */
@SuppressWarnings("unchecked")
public static <T extends View> T getViewOrNull(View parent, int viewId) {
return (T) parent.findViewById(viewId);
}
/** /**
* Same as {@link Activity#findViewById}, but crashes if there's no view. * Same as {@link Activity#findViewById}, but crashes if there's no view.
*/ */