1

I want to create a set of objects which inherit from some Android View objects. For exemple, I want to create a custom button (which I may call CustomButton) inheriting from Button. CustomButton has several parameters which Button doesn't have, let's say it contains an int called "start_count", and that a custom methods shows start_count+(the number of press actions).

A Button object is nearly always created using an XML layout. I'd like to create my CustomButton exactly the same way, with another attribute called for exemple : android:startCount="3".

I don't really know where to search. Do you happen to have a useful link or advice about this problem ?

1
  • 1
    Start out with Custom Components. The custom attributes are somewhat bad documented, so you have to google a bit around. Here is one tutorial i found by searching "android custom attributes". Commented Dec 18, 2011 at 19:13

1 Answer 1

1

You can just extend your class CustomButton from the Button class, and add to it whatever you want.

see this. You can like change text, functions, or drawables etc with for example this.setText(), or mButton.setText() (after CustomButton mButton = new... ofcourse)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.