Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getResourceId method of TypedArray

I am reading docs about getResourceId() method. It says that:

Retrieves the resource identifier for the attribute at index. Note that attribute resource as resolved when the overall TypedArray object is retrieved. As a result, this function will return the resource identifier of the final resource value that was found, not necessarily the original resource that was specified by the attribute.

So

  • the first paragraph is clear:

Retrieves the resource identifier for the attribute at index.

  • the second is clear too:

Note that attribute resource as resolved when the overall TypedArray object is retrieved.

  • but what means the 3 paragraph? why it could return not necessarily the original resource id?

As a result, this function will return the resource identifier of the final resource value that was found, not necessarily the original resource that was specified by the attribute.

like image 269
GPack Avatar asked Jun 04 '16 09:06

GPack


People also ask

What is TypedArray recycle?

The recycle() causes the allocated memory to be returned to the available pool immediately and will not stay until garbage collection. This method is also available for Bitmap .

What is TypedArray?

The JavaScript TypedArray object illustrates an array like view of an underlying binary data buffer. There are many number of different global properties, whose values are TypedArray constructors for specific element types, listed below.

What is AttributeSet?

AttributeSet (Android Docs)A collection of attributes, as found associated with a tag in an XML document. Basically if you are trying to create a custom view, and you want to pass in values like dimensions, colors etc, you can do so with AttributeSet .

What is kotlin TypedArray?

1.1. fun <T> Collection<T>. toTypedArray(): Array<T> Returns a typed array containing all of the elements of this collection. Allocates an array of runtime type T having its size equal to the size of this collection and populates the array with the elements of this collection.


1 Answers

From the documentation:

TypedArray obtainStyledAttributes (AttributeSet set, 
                int[] attrs, 
                int defStyleAttr, 
                int defStyleRes)

....

When determining the final value of a particular attribute, there are four inputs that come into play:

  1. Any attribute values in the given AttributeSet.
  2. The style resource specified in the AttributeSet (named "style").
  3. The default style specified by defStyleAttr and defStyleRes
  4. The base values in this theme.
like image 192
Kaamel Avatar answered Oct 13 '22 00:10

Kaamel