For example, dynamically from a json received from a server, a list is being played. When I clicked on a Relativelayout thread, I want to make an http request. To do this, I want to add some attribute to this Relativelayout that will contain the url I need (of the type as in html the <a> tag has href ). In the click handler, I read the element attribute I clicked on and make a request.

Found info only for the case if you use custom view. But I'm interested in, is it possible to set custom attributes with a standard view?

  • one
    No, just expanding the standard class with its implementation (make a custom View) - pavlofff

1 answer 1

No, you can't do that. Essentially, a custom attribute at the widget's code level is translated into get/set bean methods get/set

For example, the android:text attribute in TextView has as its code two methods: TextView.getText() и TextView.setText()

That is, by writing new attributes, you essentially have to rewrite the widget code, which is impossible.

Implement your own widget by inheriting from the standard one, make your own attributes in it - this is quite easy.