Skip to content

Instantly share code, notes, and snippets.

@swanson
Created August 25, 2014 13:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save swanson/acfaaac634314af7c405 to your computer and use it in GitHub Desktop.
Save swanson/acfaaac634314af7c405 to your computer and use it in GitHub Desktop.
public class ViewHelper {
@SuppressWarnings("unchecked")
public static <ViewType extends View> ViewType findView(final Activity activity, int id) {
return (ViewType) activity.findViewById(id);
}
@SuppressWarnings("unchecked")
public static <ViewType extends View> ViewType findView(final Fragment fragment, int id) {
return (ViewType) fragment.getView().findViewById(id);
}
@SuppressWarnings("unchecked")
public static <ViewType extends View> ViewType findView(final View view, int id) {
return (ViewType) view.findViewById(id);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment