File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Android and the fly likes How to use AttributeSet in constructor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Android
Bookmark "How to use AttributeSet in constructor" Watch "How to use AttributeSet in constructor" New topic
Author

How to use AttributeSet in constructor

William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12681
    
    5
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: 1369

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] | [Samuh Varta]
Monu Tripathi
Rancher

Joined: Oct 12, 2008
Posts: 1369

I have a bookmark entry which you might find interesting
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12681
    
    5
Thanks Monu, I can see that I had the wrong idea about how AttributeSet is used and that article looks helpful.

Bill
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to use AttributeSet in constructor
 
Similar Threads
ListView Problem
reading XML layout contains a SurfaceView
retrieve value from edittext from ListView
How to make TextVIew behave like EditText
How to get View from customised ListView?