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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:03:12+00:00 2026-06-01T09:03:12+00:00

This has been driving me crazy. I think I have everything in place but

  • 0

This has been driving me crazy.

I think I have everything in place but no matter what I do the touches seem to be cancelled before I lift my finger off the view. Even stranger I can draw long horizontal lines but vertical ones are always very short.

I am using a Samsung G SII 2.3.3 but building to 2.1

Ant ideas?

My sample code:

  package com.mycompany.myviews;

  import java.util.ArrayList;

  import android.content.Context;
  import android.graphics.Canvas;
  import android.graphics.Color;
  import android.graphics.Paint;
  import android.graphics.Path;
  import android.graphics.Point;
  import android.util.AttributeSet;
  import android.util.Log;
  import android.view.MotionEvent;
  import android.view.View;

  public class CustomView extends View
  {
    private ArrayList<DrawPoint> points = new ArrayList<DrawPoint>();

    public CustomView(Context context, AttributeSet attrs)
    {
      super(context, attrs);
    }

    public void addPoint(DrawPoint p)
    {
      points.add(p);
    }

      public boolean onTouchEvent (MotionEvent event)
      {
        DrawPoint p = new DrawPoint((int)event.getX(), (int)event.getY());

        switch(event.getAction())
        {
        case android.view.MotionEvent.ACTION_DOWN:
          p.start = true;
          break;

        case android.view.MotionEvent.ACTION_CANCEL:
          Log.d("TouchView", "On Touch cancelled.");
          break;
        }

        addPoint(p);
        invalidate();

        return true;
      }

    public void onDraw(Canvas c) 
    {
        super.onDraw(c);

        Path path = new Path();

        for (int i = 0; i < points.size(); i++)
        {
          DrawPoint currentPoint = points.get(i);
          if (currentPoint.start == true)
            path.moveTo(currentPoint.p.x, currentPoint.p.y);
          else
            path.lineTo(currentPoint.p.x, currentPoint.p.y);
        }

        Paint paint = new Paint();
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(2);
        paint.setColor(Color.BLACK);
        c.drawPath(path, paint);
    }

    private class DrawPoint
    {
      public boolean start = false;
      public Point p;

      DrawPoint(int x, int y)
      {
        p = new Point(x, y);
      }
    }
  }

UPDATE: OK, I figured this out. Because this view is inside another View some of the touches are being intercepted by the parent or parents.

The solution I have found to be good enough for my needs is to add the following line into the case for ACTION_DOWN :

getParent().requestDisallowInterceptTouchEvent(true);

This then allows my view to get all touches.

  • 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-01T09:03:13+00:00Added an answer on June 1, 2026 at 9:03 am

    The solution I have found to be good enough for my needs is to add the following line into the case for ACTION_DOWN :

    getParent().requestDisallowInterceptTouchEvent(true);
    

    This then allows my view to get all touches.

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

Sidebar

Related Questions

This has been driving be crazy, but I can't seem to find an answer.
This has been driving me crazy for the past few minutes I have a
This has been driving me nuts. I hope it's not been asked before but
This has been really driving me crazy. Web links work fine, but a phone
This has been driving me crazy for a few days now. I have an
Maybe this is an easy fix, but it has been driving me crazy for
This has been driving me crazy for the past couple of hours. I have
This has been driving me crazy for 2 days. I have been trying to
so I am having this issue that has been driving me crazy for hours,
I have an AutoMapper issue that has been driving me crazy for way too

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.