How to declare several stylable attributes with the same name for different tags?

Andreas

I want both my ViewA and ViewB to have the "title" tag. But I can't put this in attrs.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="ViewA">
        <attr name="title" format="string" />
    </declare-styleable>
    <declare-styleable name="ViewB">
        <attr name="title" format="string" />
        <attr name="max" format="integer" />
    </declare-styleable>
</resources>

because of the error Attribute "title" has already been defined. Another question shows this solution:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <attr name="title" format="string" />
    <declare-styleable name="ViewB">
        <attr name="max" format="integer" />
    </declare-styleable>
</resources>

but in that case, R.styleable.ViewA_title and R.styleable.ViewB_title are not generated. I need them for reading the attributes from the AttributeSet using the following code:

TypedArray a=getContext().obtainStyledAttributes( as, R.styleable.ViewA);
String title = a.getString(R.styleable.ViewA_title);

How can I solve this?

Vikram

The link you have posted does give you the correct answer. This is what it suggests you do:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <attr name="title" format="string" />
    <declare-styleable name="ViewA">
        <attr name="title" />
    </declare-styleable>
    <declare-styleable name="ViewB">
        <attr name="title" />
        <attr name="max" format="integer" />
    </declare-styleable>
</resources>

Now, R.styleable.ViewA_titleand R.styleable.ViewB_titleare both accessible.

If you get a chance, read through this answer: Link. Relevant quote:

You can define attributes in the top element or inside of a element. If I'm going to use an attr in more than one place I put it in the root element.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

JAXB Unmarshalling with outer and inner tags having same name and different attributes

From Dev

JAXB Unmarshalling with outer and inner tags having same name and different attributes

From Dev

How can I declare same object name for different class?

From Dev

Parsing xml with same tags and different attributes

From Dev

Deserializing attributes of same name but different types in Jackson?

From Dev

Deserializing attributes of same name but different types in Jackson?

From Dev

Serialize 2 properties with the same name but different attributes

From Dev

How to locate an element which have same name and same atrributes in different tags in selenium

From Dev

How is the C++ compiler's performance affected by defining several functions with the same name but different types?

From Dev

How is the C++ compiler's performance affected by defining several functions with the same name but different types?

From Dev

How to get Sibling Elements when siblings have same name but different attributes using Java and Xerces NodeIterator

From Dev

how to process xml tags with same name but different attribute values in xslt using for loop

From Dev

How to parse out the value of several attributes on different elements with xmllint/xpath?

From Dev

How to parse out the value of several attributes on different elements with xmllint/xpath?

From Dev

Why are there several modules in Perl with the same name but different file size?

From Dev

Copying attribute between different models' object but with the same attributes name

From Dev

Binding several attributes to the same element

From Dev

get stylable enum name from value

From Dev

Is there a way to differentiate between tags of the same name fetched from different remotes?

From Dev

How to access different attributes of different implementation of the same interface

From Dev

How to declare two classes with the same name in the project vb.net

From Dev

How do i declare elements with the same name(on XML) on a DTD?

From Dev

Xpath for two different attributes in 2 different tags

From Dev

for loop calling two different files (same name, different extension) across several files

From Dev

How to securely publish same npm package by several different people?

From Dev

how to rerender a template several times for different things at the same time

From Dev

How to draw several copies of the same actor on one stage at different positions?

From Dev

How to get all the data attributes with same class name jquery

From Dev

How to handle two different data-main attributes in same page?

Related Related

  1. 1

    JAXB Unmarshalling with outer and inner tags having same name and different attributes

  2. 2

    JAXB Unmarshalling with outer and inner tags having same name and different attributes

  3. 3

    How can I declare same object name for different class?

  4. 4

    Parsing xml with same tags and different attributes

  5. 5

    Deserializing attributes of same name but different types in Jackson?

  6. 6

    Deserializing attributes of same name but different types in Jackson?

  7. 7

    Serialize 2 properties with the same name but different attributes

  8. 8

    How to locate an element which have same name and same atrributes in different tags in selenium

  9. 9

    How is the C++ compiler's performance affected by defining several functions with the same name but different types?

  10. 10

    How is the C++ compiler's performance affected by defining several functions with the same name but different types?

  11. 11

    How to get Sibling Elements when siblings have same name but different attributes using Java and Xerces NodeIterator

  12. 12

    how to process xml tags with same name but different attribute values in xslt using for loop

  13. 13

    How to parse out the value of several attributes on different elements with xmllint/xpath?

  14. 14

    How to parse out the value of several attributes on different elements with xmllint/xpath?

  15. 15

    Why are there several modules in Perl with the same name but different file size?

  16. 16

    Copying attribute between different models' object but with the same attributes name

  17. 17

    Binding several attributes to the same element

  18. 18

    get stylable enum name from value

  19. 19

    Is there a way to differentiate between tags of the same name fetched from different remotes?

  20. 20

    How to access different attributes of different implementation of the same interface

  21. 21

    How to declare two classes with the same name in the project vb.net

  22. 22

    How do i declare elements with the same name(on XML) on a DTD?

  23. 23

    Xpath for two different attributes in 2 different tags

  24. 24

    for loop calling two different files (same name, different extension) across several files

  25. 25

    How to securely publish same npm package by several different people?

  26. 26

    how to rerender a template several times for different things at the same time

  27. 27

    How to draw several copies of the same actor on one stage at different positions?

  28. 28

    How to get all the data attributes with same class name jquery

  29. 29

    How to handle two different data-main attributes in same page?

HotTag

Archive