0

I have been searching around with google about this topic, but found no relevant information. It is clear to me how I can do it extending Views, but I don't want to extend anything.

I would like to somewhat "annotate" whichever android view (or whichever descendant of view) with custom properties and then retrieve their value in runtime.

Like this:

    <TextView
    custom:my_property_name="foo here"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/text_view"
    android:text="Rule" />

Then once I have a reference to this TextView I would like to call a method like:

    String myProperty = textView.getProperty("my_property_name");
    myProperty.equals("foo here");

Is this possible? How?

Thanks.

Androrider
  • 1,050
  • 2
  • 13
  • 20

1 Answers1

0

At the very least you have to create your own class that subclasses one of the standard View classes (or View itself). The existing framework code does not read attributes that are not defined by Android and that are not part of the styleable declaration for that View.

Android documentation has a page describing creating your own views with your own XML attributes: http://developer.android.com/training/custom-views/create-view.html

Karakuri
  • 38,365
  • 12
  • 84
  • 104