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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:45:40+00:00 2026-06-09T02:45:40+00:00

New to Android development, and I’m having trouble doing a simple drawing to a

  • 0

New to Android development, and I’m having trouble doing a simple drawing to a view using a canvas.

From what I’ve understood, something like this:

import android.content.Context;
import android.graphics.Canvas;
import android.view.View;

public class DrawView extends View
{
    public DrawView(Context context)
    {
        super(context);
    }

    @Override
    protected void onDraw(Canvas canvas)
    {
        super.onDraw(canvas);
        canvas.drawRGB(255,0,0);
    }
}

With this as my Activity:

public class Prototype1 extends Activity
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

And this for the layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <com.dhs2.prototype1.DrawView
        android:id="@+id/map"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        />
</LinearLayout>

Should just draw red everywhere, but instead I just get a blank screen.
Any idea where I’m going wrong?

  • 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-09T02:45:41+00:00Added an answer on June 9, 2026 at 2:45 am

    Since you added your custom view in an XML layout file, you should add 2 more constructors:

    public DrawView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }
    
    
    public DrawView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    

    This is because you pass some attributes to the view, like fill_parent, wrap_content, so the constructor public DrawView(Context context) won’t be called.

    This would work however, if you won’t declare your custom view in the XML layout file, but setting it directly from the onCreate() like this:

    setContentView(new DrawView(this));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to Android Development and I am having trouble with my XML
I am new to android development, making a simple game and using onKeyDown(.....) function
I'm new to Android development and am having an issue with my first app's
I am new to android development and I have been having issues with Force
I am new to android development. Is there a way to extends class from
I'm brand new to Android development... coming from iPhone and .Net background. I've seen
I am new to Android development and having gone through the tutorial resources at
I'm new at Android development, and I would like to know something. I know
I am new in android development. I am using Eclipse Helios and AVD 15.
I am doing Android Development using Eclipse. I have downloaded all the required software,

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.