Hi Greg, Thanks for your pointer, but it not really what I am looking for. They are defining ViewGroup in XML and then using setContentView, which calls custom components' onCreate(context, AttributeSet) constructor. I am trying to create CustomButton in Java, and if I try to manually read the attributes in the constructor, it doesn't work.
XmlPullParser parser = getResources().getXml (R.layout.custombutton); AttributeSet attributes = Xml.asAttributeSet(parser); attributes.getAttributeCount() returns -1 here. So here I'm trying to read Attributes from XML and use them in the View constructor. According to their presentation, the alternative approach is to define custom attributes as styleable, and then use that to extract the values for custom attributes. In my case, I just want to read standard Button attributes defined in an XML, not defining new attributes. Does it make sense? Zia On Jul 29, 2:09 pm, greg <sep...@eduneer.com> wrote: > Have you watched the video at > > http://www.youtube.com/watch?v=PAMtKVO2ch8 > > about creating a custom view? > > - Greg > > On Jul 29, 4:46 pm, Zia <zia.cha...@gmail.com> wrote: > > > I would like to create a widget that can reads its attributes from an > > XML file onCreate. > > > I've created a CustomButton that extends Button widget. I would like > > to define its layout and styling in an XML, such that the widget can > > be reused across different views, with the same styling attributes. > > > The notepad sample code does carry some pointers to this problem, > > however, it defines a XML layout with the component as View, inside > > LinearLayout, which is not really what I'm trying to achieve here. > > > Any suggestions or pointers for my question? > > > Thanks, > > > Zia > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---