Android Custom View Constructor

Posted by Mitch on Stack Overflow See other posts from Stack Overflow or by Mitch
Published on 2010-05-21T18:17:43Z Indexed on 2010/05/21 18:20 UTC
Read the original article Hit count: 463

Filed under:
|
|
|

I'm learning about using Custom Views from the following:

http://developer.android.com/guide/topics/ui/custom-components.html#modifying

The description says:

Class Initialization As always, the super is called first. Furthermore, this is not a default constructor, but a parameterized one. The EditText is created with these parameters when it is inflated from an XML layout file, thus, our constructor needs to both take them and pass them to the superclass constructor as well.

Is there a better description? I've been trying to figure out what the constructor(s) should look like and I've come up with 4 possible choices (see example at end of post). I'm not sure what these 4 choices do (or don't do), why I should implement them, or what the parameters mean. Is there a description of these?

Thanks.

Mitch

public MyCustomView() { super(); }

public MyCustomView(Context context) { super(context); }

public MyCustomView(Context context, AttributeSet attrs) { super(context, attrs); }

public MyCustomView(Context context, AttributeSet attrs, Map params) { super(context, attrs, params); }

© Stack Overflow or respective owner

Related posts about android

Related posts about custom-view