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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:29:13+00:00 2026-06-12T06:29:13+00:00

In trying to tackle custom views, I’m attempting to work with touch events and

  • 0

In trying to tackle custom views, I’m attempting to work with touch events and partial invalidation. For this, it’s just a row of numbers in squares spaced to fill the screen.

Now when I press on a single block, I get the block’s rectangle using this:

private Rect getDirtyRegion(float e){
    // The value is the slot number
    mValue = ((int)e / mBlockSize);

    // start X of the "stall"
    int x1 = mValue * mBlockSize;
    int y1 = 0;

    int x2 = x1 + mBlockSize;
    int y2 = getMeasuredHeight();

    return new Rect(x1, y1, x2, y2);
}

It works as expected. When there’s just a few on screen it works great. Here’s my onTouchEvent:

@Override
public boolean onTouchEvent(MotionEvent e){        

    switch(e.getAction()){
    case MotionEvent.ACTION_DOWN:
        Log.d(TAG, "ActionDown");

        setPaint(PinEntry.PAINT_PRESSED);
        invalidate(getDirtyRegion(e.getX()));
        break;

    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:

        setPaint(PinEntry.PAINT_NORMAL);
        invalidate();
        break;
    }
    return true;
}

(This has been rewritten quite a few times, so the call to invalidate without a rectangle hasn’t always been the case.)

What I’m after is, when I tap on a number, it redraws to indicate a PRESSED state by whatever I do in setPaint. When I release, reset.

When I have multiple views in a ScrollView, however it breaks. When I press and release, or even drag outside the bound (triggering ACTION_CANCEL), it resets. However, going back to that row causes the whole thing to invalidate as “PRESSED”.

Is this a TouchEvent logic issue, a drawing issue, or some combination of my inexperience with creating custom views?

  • 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-12T06:29:14+00:00Added an answer on June 12, 2026 at 6:29 am

    I ended up splitting it into two different classes, one for the container (parent), and another for each individual block and using the draw(Canvas) method of the View class.

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

Sidebar

Related Questions

I've been trying to tackle this crash and just don't know where to begin.
I have this problem I've been trying to tackle for a while. I have
I've been trying to tackle responsive design in emails and I am just having
I've been trying to tackle this for hours. Ive even looked at other similar
I am trying to tackle the Nbody example in my java class (this is
I am trying to figure out how to tackle this problem. I have to
I'm trying to figure out what the best way to tackle this would be.
Hi there guys trying to gather some ideas to tackle this problem. i am
I am trying to determine how I want to tackle this... this is all
I've been trying to tackle this problem for a day and half now and

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.