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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:05:06+00:00 2026-05-29T06:05:06+00:00

I just got started with Android and I was wondering how to use listeners

  • 0

I just got started with Android and I was wondering how to use listeners in a canvas. Particularly as part of my project, the objective is for an event to occur when we drag click from one point to another. The concept is from a game called brainvita. The game need not be understood to answer my question. All I want to know is the simplest way to make a listener for the drag clicks from one point to another on the canvas?

Do I need to map the canvas to a grid and have multiple listeners? What is the simplest way?

Additionally I’m attaching the code of the game developed so far, just the basics that help in displaying the grid!

package com.project.android.brainvita;

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

public class GameView extends View {

Paint paint = new Paint();
Paint paintF = new Paint();
Paint paintG = new Paint();
int width, height;
int MARGIN = 4;
int MARGIN_BIG = 10;
int sx = 2;

public GameView(Context context) {
    super(context);
    paint.setColor(Color.WHITE);
    paintF.setColor(Color.rgb(40, 60, 204));
    paintG.setColor(Color.rgb(240, 30, 20));
}

public void onDraw(Canvas canvas) {
    // Draw external circle
    canvas.drawCircle(width / 2, height / 2, (width - MARGIN) / 2, paintF);

    // Calculate radius of small circles
    int radius = (width - MARGIN_BIG*2) / 14;

    // Draw grid
    for (int j = -3; j <= 3; j++) {
        if (j >= -1 && j <= 1)
            for (int i = -3; i <= 3; i++) {
                canvas.drawCircle(width / 2 + (2 * radius * i), height / 2
                        + (2 * radius * j), radius - sx, paint);
            }
        else
            for (int i = -1; i <= 1; i++) {
                canvas.drawCircle(width / 2 + (2 * radius * i), height / 2
                        + (2 * radius * j), radius - sx, paint);
            }
    }
}

protected void onSizeChanged(int w, int h, int ow, int oh) {
    width = w;
    height = h;
}

}
  • 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-05-29T06:05:07+00:00Added an answer on May 29, 2026 at 6:05 am

    In android development, a canvas is used for drawing. A view is used for interacting with the user. There isn’t a direct mechanism for a canvas to receive user input. This must be handled through a view.

    You’ll want to add an onTouchListener to the View that is hosting your canvas and use that listener to store state information about touches from the user.

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

Sidebar

Related Questions

I just got started today developing for Android. I tried to make an application
I've just started learning Android development and as a little project, I'm building a
I just got started with CodeIgniter and am wondering will it slow things down
I just started a new Android project, WeekendStudy to continue learning Android development and
Just got started with Android programming and i got a task where im supposed
I've got an android project that I started from an old standard Java project,
I just started reading Effective C++ today and got to the point where the
I have just started to learn Ruby and got a good take on the
So ive just started learning python on WAMP, ive got the results of a
I just started android and I'm running into some problems. I have created a

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.