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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:34:51+00:00 2026-06-06T22:34:51+00:00

Starting to learn Canvas and have two classes so far (main one to call

  • 0

Starting to learn Canvas and have two classes so far (main one to call the view and the view)
The View class onDraw creates a target (ie number of cicles and each one coloured differently)

I have a ontouch listenerer set up to record the x and y where the user clicks

my trouble then is drawing a new circle / point where the user touches

UPDATED with classes

Main Class

public class StartScreen extends Activity {

    DrawView drawView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        drawView = new DrawView(this);
        drawView.setBackgroundColor(Color.WHITE);
        setContentView(drawView);
}

Draw Class

public class DrawView extends View implements View.OnTouchListener {

    private Paint paint[];

    private Context context;
    private Canvas canvas;

    //definging some variables

    public DrawView(Context pContext) {
        super(pContext);  
        this.context = pContext;

        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();

        paint = new Paint[5];
        setupColours();

    // setting varibale like raduis etc



    }

    private void setupColours() {

        // Creating Arrray of Paint Colours

    }

    @Override
    public void onDraw(Canvas pCanvas) {

        canvas = pCanvas;

        newRadius = radius;

        for (int i = 0; i < rings; i++) {


            if (i == 3) {
                canvas.drawCircle(centreWidth, centreHeight, newRadius, paint[0]);
            } else {
                canvas.drawCircle(centreWidth, centreHeight, newRadius, paint[1]);
            }


            canvas.drawCircle(centreWidth, centreHeight, newRadius - targetBoundary, paint[i / 2]);

            newRadius = newRadius - ringOffset;

        }

        this.setOnTouchListener(this);

    }

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        Log.d("TAG2", "x: " + event.getX() + " y: " + event.getY());
        drawHit(event.getX(), event.getY());
        return true;
    }

    public void drawHit(float hitX, float hitY) {
        Log.d("HIT", "Hit being drawn");

        Paint paint2 = new Paint();
        paint2.setColor(Color.BLACK);

        canvas.drawCircle(hitX, hitY, 100, paint2);

    }

The method is called but the circle is not being drawn. what am I doing wrong. Thanks

  • 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-06T22:34:52+00:00Added an answer on June 6, 2026 at 10:34 pm

    You have provided very little information in your question. A little elaboration wouldn’t have hurt. Are the targets(the circles) being created as you would want them to be? If yes, then get a hold of the FrameLayout and use the ‘addView’ method to overlay your ball onto the main view.

    A slightly old but nevertheless a tutorial which may be useful to you:
    http://www.kellbot.com/2009/06/android-hello-circle/

    Good Luck

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

Sidebar

Related Questions

I'm starting to learn JavaScript, so far no problem but I have a hard
I'm just starting to learn AspectJ, and I have use-case for say, User login.
I am starting to learn PHP and have a decent Java background. I came
Just starting to learn scala for a new project. Have got to the point
I am just starting to learn jQuery and have gotten some of the basic
I'm just starting to learn my way around classes now and I came across
Just starting to learn Ruby on Rails. I'm using RoR 3. I have read
I'm just starting to learn Android development. I have included a EditText component in
I am just starting to learn javascript, so I don't have the skills to
I'm starting to learn Python and I've come across generator functions, those that have

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.