Easier way to get view’s Id (string) by its Id (int)

like this:

/**
 * @return "[package]:id/[xml-id]"
 * where [package] is your package and [xml-id] is id of view
 * or "no-id" if there is no id
 */
public static String getId(View view) {
    if (view.getId() == View.NO_ID) return "no-id";
    else return view.getResources().getResourceName(view.getId());
}

I use this in view constructors to make more meaningful TAGs

Leave a Comment