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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:35:35+00:00 2026-06-04T18:35:35+00:00

i need some help on my android project. i have a canvas and i

  • 0

i need some help on my android project.
i have a canvas and i fill it with some bitmap.
and i have a pointer that drawn a line on the canvas.
my problem is how to clean the line that i’ve drawn before?
what method should i call on canvas?
i’ve tried Canvas.drawColor(), invalidate() and that’s not working.

and what is the function of Canvas.drawColor() and
Please help me solve my problem.
thanks in advance

UPDATE!
if i made the code like this:

@Override
protected void onDraw(Canvas canvas) {
    // fills the canvas with black
    canvas.drawColor(Color.BLACK);

    canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);

    canvas.drawPath(mPath, p);

    obaby.draw(canvas);
}

where i place invalidate() in my code?
and what code should i use if i want to clear the canvas using a button?

UPDATE!

i wrote my onDraw like this:

@Override
protected void onDraw(Canvas canvas) {
    canvas.drawColor(Color.BLACK);  
    if(letsdraw){
        canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
        canvas.drawPath(mPath, p);
        obaby.draw(canvas);
    }
}

and the method in reset button is like this:

public void rst(){
    letsdraw = false;
    invalidate();
    Log.v("tag", "this method called");

}

but no change in the canvas when i called the method.
did i wrote something wrong on the code above?

  • 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-04T18:35:36+00:00Added an answer on June 4, 2026 at 6:35 pm

    Make your logic like this. Draw the line on the Canvas with some condition. Check if you want to draw the line, then draw the line.

    Skeleton code –

    @Override
        protected void onDraw(Canvas canvas)
        {
            if(needToDrawLine)
            {
                //draw the line
            }
            // Other drawing stuff
        }
    

    Now just update your needToDrawLine variable and call invalidate(). You’ll get your result. Let me know if it works.

    Update:

    onDraw() method will call everytime you call the invalidate(). So everyting inside the onDraw() will execute. The way is, you have to prevent it from drawing some of the part. You’ll call invalidate() when you want to redraw the whole view, for example – button for clear the canvas.

    • canvas.drawColor(Color.BLACK); this line clear your whole view to BLACK color.

    • canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint); this line draw the bitmap at (0,0).

    • canvas.drawPath(mPath, p); this line draw the path mPath.

    • obaby.draw(canvas); some other object draw itself.

    Now – for example you want to clear the screen, when button pressed. Just initialize a variable if it draw everything. And update the variable in button click.

    public boolean drawEverything = true;
    
        @Override
        protected void onDraw(Canvas canvas) {
            canvas.drawColor(Color.BLACK);
            if(drawEverything)
            {
                canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
                canvas.drawPath(mPath, p);
                obaby.draw(canvas);
            }
        }
    
        public void buttonClicked( ... )
        {
            drawEverything = false;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help. In my android app I have a ViewFlipper that contains
I need some help with properly versioning my Android project with Git/Eclipse. I have
Need some help, please. I have a line of horizontal thumbnails loaded as ONE
i need some help in addition to android-layouts. For eyample: Actually I use a
I need some help dealing with three Threads in Android One thread is the
Need some help... I have jasperserver 4.1 installed on my ubuntu. It runs via
Need some help to solve this. I have a gridview and inside the gridview
Need some help with this problem in implementing with XSLT, I had already implemented
Need some help from javascript gurus. I have one page where http://www.google.com/finance/converter is embedded
Need some help assigning a mouseover event to display some icons that start out

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.