| Author |
How to use AttributeSet in constructor
|
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12268
|
|
In the API we see constructors like
Which looks like it ought to provide a way to create a TextView with a set of attributes taken from some XML resource.
However, I can't figure out exactly how to do that. The API just seems to lead me in circles and the book I am using is not helping.
Does anybody know of a good tutorial that could help?
Bill
|
Java Resources at www.wbrogden.com
|
 |
Monu Tripathi
Rancher
Joined: Oct 12, 2008
Posts: 1365
|
|
When you create a custom View(by extending the View class) or a container(by extending some Layout class), and use your custom class directly in the layout XMLs, your implementation will be required to have that constructor because, by default, MyView( Context c, AttributeSet a ); would be constructor that would be invoked by the system. And any attributes that you set in the XML for your custom View will be passed in the AttributeSet instance.
You can test this by extending a simple View and having your custom widget in the layout XML.
|
[List of FAQs] | [Android FAQ] | [My Blog] | [Samuh Varta]
|
 |
Monu Tripathi
Rancher
Joined: Oct 12, 2008
Posts: 1365
|
|
|
I have a bookmark entry which you might find interesting
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12268
|
|
Thanks Monu, I can see that I had the wrong idea about how AttributeSet is used and that article looks helpful.
Bill
|
 |
 |
|
|
subject: How to use AttributeSet in constructor
|
|
|