public class TypedArray extends Object
Resources.Theme.obtainStyledAttributes(AttributeSet, int[], int, int)
or Resources.obtainAttributes(android.util.AttributeSet, int[])
. Be
sure to call recycle()
when done with them.
The indices used to retrieve values from this structure correspond to
the positions of the attributes given to obtainStyledAttributes.Modifier and Type | Method and Description |
---|---|
boolean |
getBoolean(int index,
boolean defValue)
Retrieve the boolean value for the attribute at index.
|
int |
getColor(int index,
int defValue)
Retrieve the color value for the attribute at index.
|
ColorStateList |
getColorStateList(int index)
Retrieve the ColorStateList for the attribute at index.
|
float |
getDimension(int index,
float defValue)
Retrieve a dimensional unit attribute at index.
|
int |
getDimensionPixelOffset(int index,
int defValue)
Retrieve a dimensional unit attribute at index for use
as an offset in raw pixels.
|
int |
getDimensionPixelSize(int index,
int defValue)
Retrieve a dimensional unit attribute at index for use
as a size in raw pixels.
|
Drawable |
getDrawable(int index)
Retrieve the Drawable for the attribute at index.
|
float |
getFloat(int index,
float defValue)
Retrieve the float value for the attribute at index.
|
float |
getFraction(int index,
int base,
int pbase,
float defValue)
Retrieve a fractional unit attribute at index.
|
int |
getIndex(int at)
Return an index in the array that has data.
|
int |
getIndexCount()
Return the number of indices in the array that actually have data.
|
int |
getInt(int index,
int defValue)
Retrieve the integer value for the attribute at index.
|
int |
getInteger(int index,
int defValue)
Retrieve the integer value for the attribute at index.
|
int |
getLayoutDimension(int index,
int defValue)
Special version of
getDimensionPixelSize(int, int) for retrieving
ViewGroup 's layout_width and layout_height
attributes. |
int |
getLayoutDimension(int index,
String name)
Special version of
getDimensionPixelSize(int, int) for retrieving
ViewGroup 's layout_width and layout_height
attributes. |
String |
getNonConfigurationString(int index,
int allowedChangingConfigs) |
String |
getNonResourceString(int index)
Retrieve the string value for the attribute at index, but
only if that string comes from an immediate value in an XML file.
|
String |
getPositionDescription()
Returns a message about the parser state suitable for printing error messages.
|
int |
getResourceId(int index,
int defValue)
Retrieve the resource identifier for the attribute at
index.
|
Resources |
getResources()
Return the Resources object this array was loaded from.
|
String |
getString(int index)
Retrieve the string value for the attribute at index.
|
CharSequence |
getText(int index)
Retrieve the styled string value for the attribute at index.
|
CharSequence[] |
getTextArray(int index)
Retrieve the CharSequence[] for the attribute at index.
|
boolean |
getValue(int index,
TypedValue outValue)
Retrieve the raw TypedValue for the attribute at index.
|
boolean |
hasValue(int index)
Determines whether there is an attribute at index.
|
int |
length()
Return the number of values in this array.
|
TypedValue |
peekValue(int index)
Retrieve the raw TypedValue for the attribute at index
and return a temporary object holding its data.
|
void |
recycle()
Give back a previously retrieved array, for later re-use.
|
String |
toString()
Returns a string containing a concise, human-readable description of this
object.
|
public int length()
public int getIndexCount()
public int getIndex(int at)
at
- The index you would like to returned, ranging from 0 to
getIndexCount()
.getValue(int, android.util.TypedValue)
and related APIs.public Resources getResources()
public CharSequence getText(int index)
index
- Index of attribute to retrieve.public String getString(int index)
index
- Index of attribute to retrieve.public String getNonResourceString(int index)
index
- Index of attribute to retrieve.public String getNonConfigurationString(int index, int allowedChangingConfigs)
index
- Index of attribute to retrieve.allowedChangingConfigs
- Bit mask of configurations from
ActivityInfo that are allowed to change.public boolean getBoolean(int index, boolean defValue)
index
- Index of attribute to retrieve.defValue
- Value to return if the attribute is not defined.public int getInt(int index, int defValue)
index
- Index of attribute to retrieve.defValue
- Value to return if the attribute is not defined.public float getFloat(int index, float defValue)
index
- Index of attribute to retrieve.public int getColor(int index, int defValue)
ColorStateList
, then the default color from
the set is returned.index
- Index of attribute to retrieve.defValue
- Value to return if the attribute is not defined or
not a resource.public ColorStateList getColorStateList(int index)
ColorStateList
description.index
- Index of attribute to retrieve.public int getInteger(int index, int defValue)
index
- Index of attribute to retrieve.defValue
- Value to return if the attribute is not defined or
not a resource.public float getDimension(int index, float defValue)
DisplayMetrics
associated with the resources this TypedArray
object
came from.index
- Index of attribute to retrieve.defValue
- Value to return if the attribute is not defined or
not a resource.getDimensionPixelOffset(int, int)
,
getDimensionPixelSize(int, int)
public int getDimensionPixelOffset(int index, int defValue)
getDimension(int, float)
, except the returned value is converted to
integer pixels for you. An offset conversion involves simply
truncating the base value to an integer.index
- Index of attribute to retrieve.defValue
- Value to return if the attribute is not defined or
not a resource.getDimension(int, float)
,
getDimensionPixelSize(int, int)
public int getDimensionPixelSize(int index, int defValue)
getDimension(int, float)
, except the returned value is converted to
integer pixels for use as a size. A size conversion involves
rounding the base value, and ensuring that a non-zero base value
is at least one pixel in size.index
- Index of attribute to retrieve.defValue
- Value to return if the attribute is not defined or
not a resource.getDimension(int, float)
,
getDimensionPixelOffset(int, int)
public int getLayoutDimension(int index, String name)
getDimensionPixelSize(int, int)
for retrieving
ViewGroup
's layout_width and layout_height
attributes. This is only here for performance reasons; applications
should use getDimensionPixelSize(int, int)
.index
- Index of the attribute to retrieve.name
- Textual name of attribute for error reporting.public int getLayoutDimension(int index, int defValue)
getDimensionPixelSize(int, int)
for retrieving
ViewGroup
's layout_width and layout_height
attributes. This is only here for performance reasons; applications
should use getDimensionPixelSize(int, int)
.index
- Index of the attribute to retrieve.defValue
- The default value to return if this attribute is not
default or contains the wrong type of data.public float getFraction(int index, int base, int pbase, float defValue)
index
- Index of attribute to retrieve.base
- The base value of this fraction. In other words, a
standard fraction is multiplied by this value.pbase
- The parent base value of this fraction. In other
words, a parent fraction (nn%p) is multiplied by this
value.defValue
- Value to return if the attribute is not defined or
not a resource.public int getResourceId(int index, int defValue)
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.index
- Index of attribute to retrieve.defValue
- Value to return if the attribute is not defined or
not a resource.public Drawable getDrawable(int index)
Resources.getDrawable
of the owning
Resources object to retrieve its Drawable.index
- Index of attribute to retrieve.public CharSequence[] getTextArray(int index)
Resources.getTextArray
of the owning
Resources object to retrieve its String[].index
- Index of attribute to retrieve.public boolean getValue(int index, TypedValue outValue)
index
- Index of attribute to retrieve.outValue
- TypedValue object in which to place the attribute's
data.public boolean hasValue(int index)
index
- Index of attribute to retrieve.public TypedValue peekValue(int index)
TypedArray
.index
- Index of attribute to retrieve.public String getPositionDescription()
public void recycle()
public String toString()
Object
getClass().getName() + '@' + Integer.toHexString(hashCode())
See Writing a useful
toString
method
if you intend implementing your own toString
method.