Reputation: 171
I am little confused as to what -1 represents in the following arraylist. Can someone help me out please, thanks.
toyList.add(new toyStore(toyName[0], toyIcon.getResourceId(0, -1)));
toyList.add(new toyStore(toyName[1], toyIcon.getResourceId(1, -1)));
Upvotes: 0
Views: 192
Reputation: 2926
getResourceId(0, -1)
gives the resource Id at index 0 of toyIcon
or it will return -1 if the attribute is not defined or not a resource.
In the docs
public int getResourceId (int index, int defValue)
Parameters
index Index of attribute to retrieve.
defValue Value to return if the attribute is not defined or not a resource.
Returns
Attribute resource identifier, or defValue if not defined.
See this: http://developer.android.com/reference/android/content/res/TypedArray.html#getResourceId(int, int)
Similarly toyIcon.getResourceId(1, -1)
will return the resource Id at index 1 of toyIcon
or -1 if the attribute is not defined or not a resource.
Upvotes: 0
Reputation: 591
From the following link http://developer.android.com/reference/android/content/res/TypedArray.html#getResourceId(int, int)
"Value to return if the attribute is not defined or not a resource."
So basically it is a default value if what you are looking for isn't found.
Upvotes: 1
Reputation: 12073
getResourceId (int index, int defValue)
It's the defValue is stands for the Value to return if the attribute is not defined or not a resource.
more explanation :
public int getResourceId (int index, int defValue)
Added in API level 1 Retrieve 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.
Parameters index Index of attribute to retrieve. defValue Value to return if the attribute is not defined or not a resource. Returns Attribute resource identifier, or defValue if not defined.
Upvotes: 0