Hi, Yes. As you seen all views in android contains all 3 types of constructors. When you are creating your own custom view, my best practices is to create all 3 of them as all of them are used in different situation.
Start with (2) 2) View(Context,AttributeSet) - This will be called by android framework when your custom view is put into any layout xml file. As you can see, the AttributeSet is the xml parameter eg: layout_width, layout_height. 3) View(Context,AttributeSet,int defStyle) - Same as (2), however, it provides a default style given from framework. I never used this properly before, but, I guess it is the default theme/ default style provided from parent view. (Can someone shed some light here?) 1) View(Context) - The default constructor that most developer will only implements. It is mostly convenient for creating views by code instead of xml. Note: You are still free to call any of the constructor in your java code. My recommendation is at least implement (1) and (2) to use it in code and see your view changes in config mode a.k.a. design time support. On Jul 5, 1:40 pm, doles <sachin.d...@gmail.com> wrote: > Hello, > > On all views (layouts or widgets) there are three different constructors. > 1) View(Context) > 2) View(Context,AttributeSet) > 3) View(Context,AttributeSet,int defStyle) > > If I were designing and coding the first few components of an anrdoid app, > which constructors should I be mindful of implementing for re-usable > components? My constructors do have initialization logic such as setting > labels, default text and adding other widgets to layouts. Once, I call > super() in my constructor, will these three variables Context, AttributeSet > and defStyle be available to all code regardless of which constructor is > called (some might be null for the shorter constructor)? > > Hope this question makes sense. -- 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