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:
parent
c0042a2278
commit
c0491ed195
@ -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.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user