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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:12:10+00:00 2026-06-16T18:12:10+00:00

How’s it going guys. What I’m trying to do right now is increment this

  • 0

How’s it going guys. What I’m trying to do right now is increment this canvas text I have on the screen right now. I have a bitmap on the canvas that should will increment the number every time it is clicked. I printed the variable to the logcat and it is indeed incrementing but it’s not being drawn on the screen.

Here’s a picture of what I have now for better idea:

enter image description here

Here’s my drawing class:

package com.example.touchperson;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;

import android.util.Log;
import android.view.View;

public class Drawing extends View {

    Bitmap robot; 
    Rect rec;
    Paint text;
    static int touchCount = 0;
    public Drawing(Context context)  {
        super(context);
        robot = BitmapFactory.decodeResource(getResources(), R.drawable.character);
        Log.i("Robot coord", Integer.toString(robot.getHeight()));;
        rec = new Rect(0, 0, 200 , 200);
        text = new Paint();
        text.setColor(Color.CYAN);
        text.setTextSize(100);

    }


    public boolean contains(int x, int y){

        if(rec.contains(x, y)){
            return true;

        }
        else{
            return false;
        }



    }



    @Override
    protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    canvas.drawColor(Color.WHITE);
    canvas.drawBitmap(robot, rec, rec,  null);
    canvas.drawText(Integer.toString(touchCount) ,(int) (canvas.getWidth()/2) , (int) (canvas.getHeight()/2), text);


}
}

Here’s my main activity class:

package com.example.touchperson;

import android.os.Bundle;
import android.app.Activity;

import android.util.Log;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;



public class MainActivity extends Activity implements OnTouchListener {


    Drawing view;
    Drawing count;





    @Override
    protected void onCreate(Bundle savedInstanceState)  {
        super.onCreate(savedInstanceState);
        view = new Drawing(this);
        view.setOnTouchListener(this);
        setContentView(view);

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }


    @Override
    public boolean onTouch(View v, MotionEvent event) {
        // TODO Auto-generated method stub

        switch(event.getAction()){
        case MotionEvent.ACTION_DOWN:

            if(view.contains((int) event.getX(), (int) event.getY())){

                Drawing.touchCount++;
                count = new Drawing(this);
                Log.i("touched", Integer.toString(Drawing.touchCount));
            }
            break;


        }
        return false;
    }



}

Any help would be much appreciated.

  • 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-16T18:12:12+00:00Added an answer on June 16, 2026 at 6:12 pm

    You should add an update method to your Drawing class and then update the number you paint in that method. You probably also need to invalidate the region your Drawing class has painted to have the new number appear on the screen (to force your onDraw to be called again).

    Like Squonk said, you have 2 instances of your Drawing class right now, and one is in the layout of the screen at all (only “view” is).

    Aside from this though, I would add an ImageButton to show the robot, and then a TextView to show the number and add those elements to the layout of the activity. When the ImageButton is clicked, then I’d simply set the Text property of the TextView to the next number. Writing a customized View object is only required when you are rendering something that you can’t compose from the out-of-the-box components.

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

Sidebar

Related Questions

this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
I have a small JavaScript validation script that validates inputs based on Regex. I
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.