I have  a style

<style name="MyText">
    <item name="android:background">#ffc0c0c0</item>
    <item name="android:textColor">#ffff8080</item>
</style>

which I am trying to introspect in my ocde.  I use this code to retrieve 
typed array:

final Resources.Theme theme = getActivity().getTheme();
final int[] attrs = {android.R.attr.textColor, android.R.attr.background,};
final TypedArray a = theme.obtainStyledAttributes(null, attrs, 0, 
R.style.MyText);
try {
    Log.d(TAG, "length: " + a.length());
    for (int i = 0; i < a.length(); ++i) {
        final TypedValue v = a.peekValue(i);
        if (v != null) {
            Log.d(TAG, "type: " + v.type);
        }
        Log.d(TAG, "---------------------------------");
    }

} finally {
    a.recycle();
}

The output is:

D/PlaceholderFragment( 3391): length: 2
D/PlaceholderFragment( 3391): type: 28
D/PlaceholderFragment( 3391): ---------------------------------
D/PlaceholderFragment( 3391): type: 28
D/PlaceholderFragment( 3391): ---------------------------------

Everything seems fine at this point.  But when I change the order of the 
attribute in the array from

final int[] attrs = {android.R.attr.textColor, android.R.attr.background,};

to

final int[] attrs = {android.R.attr.background, android.R.attr.textColor,};

the output becomes

D/PlaceholderFragment( 3528): length: 2
D/PlaceholderFragment( 3528): type: 28
D/PlaceholderFragment( 3528): ---------------------------------
D/PlaceholderFragment( 3528): ---------------------------------

The second TypedValue returned by the peekValue() method becomes null in 
the second case.  Why?  What am I doing wrong?

Thank you!

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to