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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:46:52+00:00 2026-06-01T04:46:52+00:00

I have something to draw at runtime. I did drawing in onDraw in MyView

  • 0

I have something to draw at runtime. I did drawing in onDraw in MyView class.
Because, I already used setContentView(R.layout.main) in onCreate, I cannot use it again.
How to call onDraw after setContentView(R.layout.main)?

public class MyActivity extends Activity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main); // I have something to draw in XML also.
        MyView myView = new MyView(this);
        // setContentView(myView); I cannot use setContentView two times.
}
protected class MyView extends View {
    public MyView(Context context) {
        super(context);
    }
    public void onDraw(Canvas canvas) {
           // there are some drawing codes and these cannot be done in XML.
    }
}
  • 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-01T04:46:53+00:00Added an answer on June 1, 2026 at 4:46 am

    I see two ways

    1:
    You could add your myView (instance) to an ViewGroup defined in R.layout.main

    2:
    You could directly add use MyView in your XML R.layout.main.
    Instead of “LinearLayout” and so on, you the full qualified class name

    see http://developer.android.com/guide/topics/ui/custom-components.html (at bottom)

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

Sidebar

Related Questions

I have a class that holds the size and position of something I draw
I have a PictureBox control on a Form that is supposed to draw something
I have something like this set up: class CategoryPage (webapp.RequestHandler): def get(self): ** DO
I have something that looks like the following: [CoolnessFactor] interface IThing {} class Tester
As far as I have understood so far, every time I draw something in
I'm trying to draw something on a map using overlays. So I have the
I have something similar to a drawing canvas, and I capture it's state on
I have to write a simple program that will draw something in a Windows
I want to draw something on an <mx:Image> I have in my .mxml file,
I want to draw a square in Assembly language. I have ridden something about

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.