Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6802195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:11:39+00:00 2026-05-26T19:11:39+00:00

I have my custom view extended from View . There are 3 view constructors:

  • 0

I have my custom view extended from View. There are 3 view constructors:

  1. View(Context context, AttributeSet attrs, int defStyle)
  2. View(Context context, AttributeSet attrs)
  3. View(Context context)

From my activity I call std.setContentView(R.layout.main). The second constructor is getting called in my view. Why the second one? How to know in advance which one will be called and why?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T19:11:40+00:00Added an answer on May 26, 2026 at 7:11 pm

    From the Android developer site under documentation for View:

    public View (Context context)

    Simple constructor to use when creating a view from code.

    So this constructor is what you can use to create a View in Java. It will not be called when you inflate from XML.

    public View (Context context, AttributeSet attrs)

    Constructor that is called when inflating a view from XML. This is called when a view is being constructed from an XML file, supplying attributes that were specified in the XML file. This version uses a default style of 0, so the only attribute values applied are those in the Context’s Theme and the given AttributeSet.

    The method onFinishInflate() will be called after all children have been added.

    So this constructor will be called when you inflate a View from XML when you don’t specify a style.

    public View (Context context, AttributeSet attrs, int defStyle)

    Perform inflation from XML and apply a class-specific base style. This constructor of View allows subclasses to use their own base style when they are inflating. For example, a Button class’s constructor would call this version of the super class constructor and supply R.attr.buttonStyle for defStyle; this allows the theme’s button style to modify all of the base view attributes (in particular its background) as well as the Button class’s attributes.

    You should implement all of these constructors, but you can put all of the work in the third one by calling this(context, null) and this(context, attrs, 0) for the first two, respectively.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom View Engine that derives from WebFormViewEngine. There's a lot of
I have the following situation: There is one custom view inside of the first
I have a custom view called DrawView created in the main activity. I have
I have custom table view cell with images (loaded from app document directory), labels,
I have a custom view public GraphView(Context context, float[] values, String title, String[]horlabels, String[]
I have an extended from BaseAdapter class which used as a custom Adapter for
I have extended View to build a custom widget. I would like to define
I have a custom view which I call Node that is a child of
I have a custom view subclassed from GridView that I use in order to
I have a custom view engine in ASP.NET MVC and since upgrading to RC1

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.