code: public static int getResourceId(Resources.Theme theme, TypedArray a, TypedValue[] values, int index, int def) {
          if (values != null && theme != null) {
              TypedValue v = values[index];
              if (v.type == TypedValue.TYPE_ATTRIBUTE) {
                  TEMP_ARRAY[0] = v.data;
                  TypedArray tmp = theme.obtainStyledAttributes(null, TEMP_ARRAY, 0, 0);
                  try {
                      return tmp.getResourceId(0, def);
                  } finally {
                      tmp.recycle();
                  }
              }
          }
  
          if (a != null) {
              return a.getResourceId(index, def);
          }
  
          return def;
      }
docs: Retrieve the resource identifier for the attribute at
  <var>index</var>.  Note that attribute resource as resolved when
  the overall {@link TypedArray} object is retrieved.  As a result, this function will return
  the resource identifier of the final resource value that was found, <em>not</em> necessarily
  the original resource that was specified by the attribute.
  
  @param index Index of attribute to retrieve.
  @param def   Value to return if the attribute is not defined or not a resource.
  @return Attribute resource identifier, or defValue if not defined.