vlio20
vlio20

Reputation: 9295

Extending an existing element class in Android

Lets say I want to extend an e,element calls in Android, For example the Button element. So I have this class:

Class MyButton extends Button{
     ...

}

So when I want to use this element I should in the layout xml file put:

<MyButton/>

or

<Button>

Thanks!

Upvotes: 0

Views: 85

Answers (3)

qzikl
qzikl

Reputation: 651

You should check this site for lots more on custom views: http://developer.android.com/training/custom-views/create-view.html

You'll need to use the full classpath in this case, but you should check that reference for a lot more information on a custom view.

Upvotes: 2

rekire
rekire

Reputation: 47965

You can add it like this here:

<you.package.MyButton>

Note that you need to implement the both constructors with the xml attributes else this won't work:

//Constructor that is called when inflating a view from XML.
View(Context context, AttributeSet attrs)

//Perform inflation from XML and apply a class-specific base style.
Vew(Context context, AttributeSet attrs, int defStyle)

Upvotes: 2

Jave
Jave

Reputation: 31846

You will have to use the fully qualified classname, so:

<my.application.package.MyButton>

And make sure that your class is public.

Upvotes: 4

Related Questions