Android AttributeSet API

Source: Internet
Author: User

Android AttributeSet API
Android AttributeSet API
Public interfaceAttributeSet

Android. util. AttributeSet
Known indirect subclass XmlResourceParser
Class Overview

A set of attributes is usually used in xml documents. Generally, you do not want to use it directly, but use it by Resources. Theme. obtainStyledAttributes () that can explain the attributes for you. In particular, the Resources API will convert the referenced Resources (like "@ string/my_label" in the. xml file) to your desired type. If you use AttributeSet directly, you need to manually check your resource application (through getAttributeResourceValue (int, int), and you need to find the resource yourself if necessary. Using AttributeSet directly will also damage the themes and styles of the Application during attribute check.

This interface also provides Xml by using XmlPullParser. the asAttributeSet () method is efficient from compiled. the xml file data retrieval mechanism usually returns an interface implemented through XmlPullParser, but it is more useful when compiling XML resources:

 XmlPullParser parser = resources.getXml(myResouce); AttributeSet attributes = Xml.asAttributeSet(parser);

This implementation method is not like the integrated implementation of XmlPullParser. When compiling your resources, it efficiently optimizes the search for the budget information generated by the appt, such as getAttributeFloatValue (int, float) the returned result is a floating point number that has been stored in your compilation resources, rather than the runtime. /original string in xml file

This excuse also provides additional information contained in the compiled xml file that does not exist in the original xml file. For example, getAttributeNameResource (int) returns the Resource Identifier attribute name associated with the specific XML.

Overview
Public Method
Abstract boolean GetAttributeBooleanValue (String namespace, String attribute, boolean defaultValue) Returns the Boolean value of 'attribute'. The default value is defaultValue.
Abstract boolean GetAttributeBooleanValue (int index, boolean defaultValue) Returns the Boolean value of 'attribute' whose serial number is index. The default value is defaultValue.
Abstract int GetAttributeCount () Returns the number of attributes in the attribute set.
Abstract float GetAttributeFloatValue (int index, float defaultValue) Return the float value of attribute at 'index '.
Abstract float GetAttributeFloatValue (String namespace, String attribute, float defaultValue) Return the float value of 'attribute '.
Abstract int GetAttributeIntValue (String namespace, String attribute, int defaultValue) Return the integer value of 'attribute '.
Abstract int GetAttributeIntValue (int index, int defaultValue) Return the integer value of attribute at 'index '.
Abstract int GetAttributeListValue (String namespace, String attribute, String [] options, int defaultValue) Return the index of the value of 'attribute' in the list 'options '.
Abstract int GetAttributeListValue (int index, String [] options, int defaultValue) Return the index of the value of attribute at 'index' in the list'options '.
Abstract String GetAttributeName (int index) Returns the name of the specified attribute.
Abstract int GetAttributeNameResource (int index) Return the resource ID associated with the given attribute name.
Abstract int GetAttributeResourceValue (String namespace, String attribute, int defaultValue) Return the value of 'attribute' as a resource identifier.
Abstract int GetAttributeResourceValue (int index, int defaultValue) Return the value of attribute at 'index' as a resource identifier.
Abstract int GetAttributeUnsignedIntValue (int index, int defaultValue) Return the integer value of attribute at 'index' that is formatted as an unsigned value.
Abstract int GetAttributeUnsignedIntValue (String namespace, String attribute, int defaultValue) Return the boolean value of 'attribute' that is formatted as an unsigned value.
Abstract String GetAttributeValue (int index) Returns the value of the specified attribute as a string representation.
Abstract String GetAttributeValue (String namespace, String name) Returns the value of the specified attribute as a string representation.
Abstract String GetClassAttribute () Return the value of the "class" attribute or null if there is not one.
Abstract String GetIdAttribute () Return the value of the "id" attribute or null if there is not one.
Abstract int GetIdAttributeResourceValue (int defaultValue) Return the integer value of the "id" attribute or defaultValue if there is none.
Abstract String GetPositionDescription () Returns a description of the current position of the attribute set.
Abstract int GetStyleAttribute () Return the value of the "style" attribute or 0 if there is not one.
Public method public abstract boolean getAttributeBooleanValue (String namespace, String attribute, boolean defaultValue) added to API Level 1

Return the boolean value of 'attribute '.

Parameters
Namespace The 'attribute' namespace to be retrieved
Attribute The 'attribute' to be retrieved'
DefaultValue Default return value not found in 'attribute'
Return Value
  • Resulting value. public abstract boolean getAttributeBooleanValue (int index, boolean defaultValue) added to API Level 1

    Return the boolean value of attribute at 'index '.

    Parameters
    Index Index of the desired attribute, 0... count-1.
    DefaultValue What to return if the attribute isn' t found.
    Return Value
    • Resulting value. public abstract int getAttributeCount () added to API Level 1

      Returns the number of attributes available in the set.

      Return Value
      • A positive integer, or 0 if the set is empty. public abstract float getAttributeFloatValue (int index, float defaultValue) is added to API Level 1

        Return the float value of attribute at 'index '.

        Parameters
        Index Index of the desired attribute, 0... count-1.
        DefaultValue What to return if the attribute isn' t found.
        Return Value
        • Resulting value. public abstract float getAttributeFloatValue (String namespace, String attribute, float defaultValue) added to API Level 1

          Return the float value of 'attribute '.

          Parameters
          Namespace Namespace of attribute to retrieve.
          Attribute The attribute to retrieve.
          DefaultValue What to return if the attribute isn' t found.
          Return Value
          • Resulting value. public abstract int getAttributeIntValue (String namespace, String attribute, int defaultValue) added to API Level 1

            Return the integer value of 'attribute '.

            Parameters
            Namespace Namespace of attribute to retrieve.
            Attribute The attribute to retrieve.
            DefaultValue What to return if the attribute isn' t found.
            Return Value
            • Resulting value. public abstract int getAttributeIntValue (int index, int defaultValue) added to API Level 1

              Return the integer value of attribute at 'index '.

              Parameters
              Index Index of the desired attribute, 0... count-1.
              DefaultValue What to return if the attribute isn' t found.
              Return Value
              • Resulting value. public abstract int getAttributeListValue (String namespace, String attribute, String [] options, int defaultValue) added to API Level 1

                Return the index of the value of 'attribute' in the list 'options '.

                Parameters
                Namespace Namespace of attribute to retrieve.
                Attribute Name of attribute to retrieve.
                Options List of strings whose values we are checking against.
                DefaultValue Value returned if attribute doesn't exist or no match is found.
                Return Value
                • Index in to 'options' or defaultValue. public abstract int getAttributeListValue (int index, String [] options, int defaultValue) added to API Level 1

                  Return the index of the value of attribute at 'index' in the list'options '.

                  Parameters
                  Index Index of the desired attribute, 0... count-1.
                  Options List of strings whose values we are checking against.
                  DefaultValue Value returned if attribute doesn't exist or no match is found.
                  Return Value
                  • Index in to 'options' or defaultValue. public abstract String getAttributeName (int index) added to API Level 1

                    Returns the name of the specified attribute.

                    Parameters
                    Index Index of the desired attribute, 0... count-1.
                    Return Value
                    • A String containing the name of the attribute, or null if the attribute cannot be found. public abstract int getAttributeNameResource (int index) is added to API Level 1

                      Return the resource ID associated with the given attribute name. This will be the identifier for an attribute resource, which can be used by styles. Returns 0 if there is no resource associated with this attribute.

                      Note that this is differentgetAttributeResourceValue(int, int)In that it returns a resource identifier for the attribute name; the other method returns this attribute's value as a resource identifier.

                      Parameters
                      Index Index of the desired attribute, 0... count-1.
                      Return Value
                      • The resource identifier, 0 if none. public abstract int getAttributeResourceValue (String namespace, String attribute, int defaultValue) is added to API Level 1

                        Return the value of 'attribute' as a resource identifier.

                        Note that this is differentgetAttributeNameResource(int)In that it returns a value contained in this attribute as a resource identifier (I. e ., a value originally of the form "@ package: type/resource"); the other method returns a resource identifier that identifies the name of the attribute.

                        Parameters
                        Namespace Namespace of attribute to retrieve.
                        Attribute The attribute to retrieve.
                        DefaultValue What to return if the attribute isn' t found.
                        Return Value
                        • Resulting value. public abstract int getAttributeResourceValue (int index, int defaultValue) added to API Level 1

                          Return the value of attribute at 'index' as a resource identifier.

                          Note that this is differentgetAttributeNameResource(int)In that it returns a value contained in this attribute as a resource identifier (I. e ., a value originally of the form "@ package: type/resource"); the other method returns a resource identifier that identifies the name of the attribute.

                          Parameters
                          Index Index of the desired attribute, 0... count-1.
                          DefaultValue What to return if the attribute isn' t found.
                          Return Value
                          • Resulting value. public abstract int getAttributeUnsignedIntValue (int index, int defaultValue) added to API Level 1

                            Return the integer value of attribute at 'index' that is formatted as an unsigned value. In particle, the formats 0xn... n and # n... n are handled.

                            Parameters
                            Index Index of the desired attribute, 0... count-1.
                            DefaultValue What to return if the attribute isn' t found.
                            Return Value
                            • Resulting value. public abstract int getAttributeUnsignedIntValue (String namespace, String attribute, int defaultValue) added to API Level 1

                              Return the boolean value of 'attribute' that is formatted as an unsigned value. In particle, the formats 0xn... n and # n... n are handled.

                              Parameters
                              Namespace Namespace of attribute to retrieve.
                              Attribute The attribute to retrieve.
                              DefaultValue What to return if the attribute isn' t found.
                              Return Value
                              • Resulting value. public abstract String getAttributeValue (int index) added to API Level 1

                                Returns the value of the specified attribute as a string representation.

                                Parameters
                                Index Index of the desired attribute, 0... count-1.
                                Return Value
                                • A String containing the value of the attribute, or null if the attribute cannot be found. public abstract String getAttributeValue (String namespace, String name) is added to API Level 1

                                  Returns the value of the specified attribute as a string representation. The lookup is already med using the attribute name.

                                  Parameters
                                  Namespace The namespace of the attribute to get the value from.
                                  Name The name of the attribute to get the value from.
                                  Return Value
                                  • A String containing the value of the attribute, or null if the attribute cannot be found. public abstract String getClassAttribute () is added to API Level 1

                                    Return the value of the "class" attribute or null if there is not one. Equivalent to getAttributeValue (null, "class ").

                                    Return Value
                                    • The class attribute's value or null. public abstract String getIdAttribute () added to API Level 1

                                      Return the value of the "id" attribute or null if there is not one. Equivalent to getAttributeValue (null, "id ").

                                      Return Value
                                      • The id attribute's value or null. public abstract int getIdAttributeResourceValue (int defaultValue) is added to API Level 1

                                        Return the integer value of the "id" attribute or defaultValue if there is none. Equivalent to getAttributeResourceValue (null, "id", defaultValue );

                                        Parameters
                                        DefaultValue What to return if the "id" attribute isn't found.
                                        Return Value
                                        • Int Resulting value. public abstract String getPositionDescription () added to API Level 1

                                          Returns a description of the current position of the attribute set. For instance, if the attribute set is loaded from an XML document, the position description cocould indicate the current line number.

                                          Return Value
                                          • A string representation of the current position in the set, may be null. public abstract int getStyleAttribute () added to API Level 1

                                            Return the value of the "style" attribute or 0 if there is not one. Equivalent to getAttributeResourceValue (null, "style ").

                                            Return Value
                                            • The style attribute's resource identifier or 0.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.