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

  • Home
  • SEARCH
  • 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 6801529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:06:41+00:00 2026-05-26T19:06:41+00:00

The problem that i am having is I am using a touch listener for

  • 0

The problem that i am having is I am using a touch listener for the onTouch event it seems that the touch is being called more than once when i just touch it once.
The following is my code

final TextView tv = (TextView)findViewById(R.id.TextView01);

        tv.setOnTouchListener(new View.OnTouchListener() {
            int count1 =0;
            int count2=0;
            public boolean onTouch(View arg0, MotionEvent event) {
                Log.d("Code777","Touch is being called finger");
                int i = event.getPointerCount();



                if(i==1 )
                {
                    if(count1==0)
                    {
                        Log.d("Code777","Touched with 1 finger");
                        count1++;
                        count2=0;
                    }

                }

                 if (i==2 )
                {
                     if(count2==0)
                     {
                        Log.d("Code777","Touched with 2 fingers");
                        edit.append(tv.getText());  
                        count2++;
                        count1=0;
                     }
                }
                return true;
            }
        });

Am i doing something wrong ??
It prints the log more than 3-4 times for both single touch and double touch

The problem updated problem is that both the events are getting fired now

  if(event.getAction() == MotionEvent.ACTION_POINTER_2_DOWN)
                {
                    Log.d("Code777","2 finger touch");
                    return true;
                }else if(event.getAction() == MotionEvent.ACTION_DOWN)
                {
                        Log.d("Code777","Touched with 1 finger");


                    return true;
                }
  • 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-26T19:06:42+00:00Added an answer on May 26, 2026 at 7:06 pm

    You’re code will execute during every touch event. The first time it activates, it’s likely do to an ACITON_DOWN event (when the user first touches the screen). The second time, it is likely do to an ACTION_UP event (when the user lifts the finger from the screen). Likewise, if you were to swipe your finger around the screen, the same code will execute many times for an ACTION_MOVE event. You have to check for the types of touches that it is. Do something like this:

    switch(event.getAction()){
       case MotionEvent.ACTION_DOWN:
         // Do something that should only happen when the user first touches the screen
         break;
       case MotionEvent.ACTION_MOVE:
         // Do something that should only happen when the user is touching the screen
         break;
       case MotionEvent.ACTION_UP:
         // Do something that should only happen when the user stops touching the screen
         break;
    }
    

    EDIT:

    Multitouch in Android is odd at best. Not all devices can handle it. Not all device can handle more than x number of touches, etc. If you want to handle DOWN cases for individual fingers, then you can use the ACTION_POINTER_X items. If you were to have this series of events like so:

    1.  User touches screen
    2.  User touches screen with second finger
    3.  User lifts finger 1
    4.  User touches screen with finger 1
    5.  User lifts finger 2
    6.  User touches screen with finger 2
    7.  User lifts both finger 1 and finger 2
    8.  User touches screen with only finger 2
    9.  User touches screen with finger 1
    

    The events that will be fired will be like this:

    1.  ACTION_DOWN
    2.  ACTION_POINTER_2_DOWN
    3.  ACTION_POINTER_1_UP
    4.  ACTION_POINTER_1_DOWN
    5.  ACTION_POINTER_2_UP
    6.  ACTION_POINTER_2_DOWN
    7.  ACTION_UP (also, one of the pointers actions will fire depending on which finger was lifted first)
    8.  ACTION_DOWN
    9.  ACTION_POINTER_2_DOWN
    

    And so on.

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

Sidebar

Related Questions

I'm having problems using textures that are larger than the OpenGL window or the
I am having a problem that just started happening in OS 3.1. I have
I using jQuery-UI sortable which works fine. The problem that I am having is
I'm having the weird problem that after having javascript inject some dom-elements the css-rules
The problem that I am having has to do with the need to keep
I am having problem that when i am trying to submit the form by
My problem is that I have a user that is having a problem displaying
I've been thinking/searching for an equivalent of the problem that I am having below,
HI Guys, Here I am having problem that How can I post an image
Dear Friends from Stackoverflow, Please help me with a problem that i'm having when

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.