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 8696259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:14:14+00:00 2026-06-13T01:14:14+00:00

EDIT: I was missing a key concept, the message queue, while creating my custom

  • 0

EDIT: I was missing a key concept, the message queue, while creating my custom view and trying to update the view without using it turned out being the source of the issue I was having. This gets cleared up here:

Android: Writing Custom Views that Support The Message Queue

It turns out that you need to let the runtime/android call OnMeasure after OnCreate exits (“like normal”), and in the mean time put any updates to the view in the message queue via the .post method.

So, you can grab a handle to the view, via FindViewById, in OnCreate as usual, and then
post any updates to it (either through overrides like setText, or your own set functions)
within a runnable (see above link).


I’ve been working on a custom view in android for quite some time now and have throughly experimented with constructors, attributes, layout parameters, and drawing methods (OnMeasure, OnLayout, …).

The parent-most viewgroup (the one declared in the layout file for rendering) inherits from RelativeLayout and contains three child views, all custom/inherited viewgroups as well, and so on.

I’m implementing a custom calendar (I know, very original and exciting), I’ll call CustomCalendar. So, in my layout file I have the statment

<MonoDroid.CustomViews.CustomCalendar
  xmlns:calendar="http://schemas.android.com/apk/res/net.monocross.appname"
  android:id="+id/Calendar1"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  calendar:row_count="5"
  calendar:col_count="7"
 ...
/>

This view resides along side a few others that are defined in the layout file as well, and thus the source of my complication, which will be stated now.

I’m trying to figure out how to get this view’s dimensions before OnMeasure is called (where I can get them no problem, however because the layout dimensions of the children views are determined from this views dimensions, I cannot instantiate the childeren views until the first time OnMeasure is called, and this proves to be after I need it; after OnCreate exits).

That is, after calling SetContentView in OnCreate, and then instantiating the custom view from it via FindViewById(Resource.Id.Calendar1), the child views do not get instantiated as well if its done from the OnMeasure override (again, b/c OnMeasure isn’t called until after OnCreate returns).

If I read the attributes passed into the constructor, alls I get from layout_width and layout_height are the constant -1 for fill_parent. I cannot just use the entire screen either, because there are other views to compensate for.


Therefore, I’m looking for the best approach in determining the dimensions of a custom view from within its constructor so that I can instantiate all of the view’s childern from it (the constructor) with the proper layout dimensions so that the views are available from OnCreate (for updating with content) after SetContentView is called and before returning from OnCreate.

Another means to the same end will be fine with me, though I’m kinda looking to do this the way the infrastructure intends it to be (if there is such a thing).

  • 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-06-13T01:14:15+00:00Added an answer on June 13, 2026 at 1:14 am

    You can’t get dimensions in the constructor. At best, if they are defined in XML, you could get the layout width and height from the AttributeSet.

    What you should be doing is overriding onMeasure and onLayout. You can do whatever calculations and setup you need in onMeasure, then pass the calculated values to measureChild(view, widthSpec, heightSpec). and you can mess with layout stuff in onLayout then call childView.layout(left, top, right, bottom).

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

Sidebar

Related Questions

EDIT: See my answer below--> I am wanting to have a view that when
EDIT: iam using ajax to load text in my content that is why onload
EDIT : It turned out that this can only be done through an external
I've been encountering some strange behavior when trying to find a key inside a
i'm trying to close the browser window with the ESC key, but dont know
I am trying to auto scroll my text view and reset it to the
Hopefully I'm not missing something obvious... I'm creating a function that will ease in
I am using a method like this private static <T> void setPreference(String key, T
We're seeing the error message ORA-00936 Missing Expression for the following SQL: Note that
So I thought I had covered my bases, but apparently I'm missing a key

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.