Skip to content

Instantly share code, notes, and snippets.

@JeffMcKnight
Created July 2, 2019 17:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JeffMcKnight/b032ae33f4d4f99360e698e32a6959d0 to your computer and use it in GitHub Desktop.
Save JeffMcKnight/b032ae33f4d4f99360e698e32a6959d0 to your computer and use it in GitHub Desktop.
Static method to return the Tag attribute of an Android View, or, if that is missing, return the name of the ID attribute
public class ViewUtil {
public static String getTagOrIdName(View view) {
if (view != null) {
if (view.getTag() != null) {
return view.getTag().toString();
} else {
return view.getResources().getResourceEntryName(view.getId());
}
} else {
return "null";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment