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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:50:32+00:00 2026-06-01T07:50:32+00:00

I used the following code to detect the single finger touch and double finger

  • 0

I used the following code to detect the single finger touch and double finger touch. The code detects the double finger touch (when count==2).

I need to do some action on single touch also. If I touch the screen with one finger it doesn’t go for the else part. What have I done wrong in this code?

@Override
public boolean onTouchEvent(MotionEvent event) {
    int action = event.getAction() & MotionEvent.ACTION_MASK;
    switch (action) {
        case MotionEvent.ACTION_POINTER_UP: {
            int count = event.getPointerCount();
            Log.v("count >>", count + "");
            if (count == 2) {
                // some action
            } else {
                Log.v("count not equal to 2", "not 2");
            }
            break;
        }
    }
    return true;
}

Update:

I used this code inside an Activity. I need to detect single touch, multitouch.

In my activity, I have two images, one on the left and one on the right. If I click the image some process has to do. If I use two fingers, I need to re-size the images, according to the scale-factor.

This is the code that I’ve used:

Updated:

package com.pinch.detect;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.FloatMath;
import android.util.Log;
import android.view.Display;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.View;
import android.view.ScaleGestureDetector.SimpleOnScaleGestureListener;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class PinchDetectorActivity extends Activity {
    TextView textGestureAction;
    ImageView img1, img2;
    static Bitmap bm, bm1;

    boolean multiTouch = false;
    Context context;
    float scaleFactor = 0.0f;
    float lastscale;
    int scr_width, scr_height;
    Display display;
    private ScaleGestureDetector scaleGestureDetector;

    /** Called when the activity is first created. */

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        textGestureAction = (TextView) findViewById(R.id.GestureAction);
        img1 = (ImageView) findViewById(R.id.img_left);
        img2 = (ImageView) findViewById(R.id.img_right);
        display = getWindowManager().getDefaultDisplay();

        scr_width = display.getWidth();
        scr_height = display.getHeight();
        Log.v("width >>", Integer.toString(scr_width));
        Log.v("height >>", Integer.toString(scr_height));

        bm = BitmapFactory.decodeResource(this.getResources(),
                R.drawable.fiction1);
        img1.setImageBitmap(bm);
        bm1 = BitmapFactory.decodeResource(this.getResources(),
                R.drawable.fiction2);
        img2.setImageBitmap(bm1);
        img1.setScaleType(ImageView.ScaleType.FIT_START);
        img2.setScaleType(ImageView.ScaleType.FIT_END);

        scaleGestureDetector = new ScaleGestureDetector(this,
                new MySimpleOnScaleGestureListener());



        img1.setOnTouchListener(new OnTouchListener(){

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

        });
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {

        scaleGestureDetector.onTouchEvent(event);
        int index = event.getActionIndex();
        Log.v("Index value ",index+"");
        int action = event.getAction();

        if (index == 1) {
            multiTouch = true;
            System.out.println("mutli1");
        } else if (multiTouch == false) {
            System.out.println("single1");
            img1.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    Log.v("clicked image1","img1>>>");
                }
            });
            img2.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) { // TODO Auto-generated method
                    Log.v("clicked image2","img2>>>");
                }
            });
        }

         else if (action == MotionEvent.ACTION_MOVE && multiTouch) {
            System.out.println("mutli2");


            if (scaleFactor > 1) {

                Bitmap resizedbitmap = Bitmap.createScaledBitmap(bm,
                        scr_width / 2, scr_height, true);
                img1.setImageBitmap(resizedbitmap);
                Bitmap resizedbitmap1 = Bitmap.createScaledBitmap(bm1,
                        scr_width / 2, scr_height, true);
                img2.setImageBitmap(resizedbitmap1);
                Log.v("width >>", Integer.toString(scr_width));
                Log.v("height >>", Integer.toString(scr_height));

            } else if(scaleFactor<1){

                Log.v("width >>", Integer.toString(scr_width));
                Log.v("height >>", Integer.toString(scr_height));
                if (scr_width >= 640) {
                    Bitmap resizedbitmap = Bitmap.createScaledBitmap(bm,
                            scr_height + 90, scr_height, true);

                    img1.setImageBitmap(resizedbitmap);

                    Bitmap resizedbitmap1 = Bitmap.createScaledBitmap(bm1,
                            scr_height + 90, scr_height, true);

                    img2.setImageBitmap(resizedbitmap1);
                } else {
                    Bitmap resizedbitmap = Bitmap.createScaledBitmap(bm,
                            scr_height, scr_height + 30, true);

                    img1.setImageBitmap(resizedbitmap);

                    Bitmap resizedbitmap1 = Bitmap.createScaledBitmap(bm1,
                            scr_height, scr_height + 30, true);

                    img2.setImageBitmap(resizedbitmap1);
                }

            }



        } else if (action == MotionEvent.ACTION_MOVE && !multiTouch)
        {
            System.out.println("single2");
        }

        return super.onTouchEvent(event);

    }

    public class MySimpleOnScaleGestureListener extends
            SimpleOnScaleGestureListener {

        @Override
        public boolean onScale(ScaleGestureDetector detector) {
            // TODO Auto-generated method stub

            scaleFactor = detector.getScaleFactor();

            Log.v("scaleFactor >>>", scaleFactor + "");

            return true;
        }
    }

}

and my main.xml is

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:id="@+id/pinchlay" >


    <ImageView
        android:id="@+id/img_left"
        android:layout_width="320dp"
        android:layout_height="fill_parent"
        />

    <ImageView
        android:id="@+id/img_right"
        android:layout_width="320dp"
        android:layout_height="fill_parent"
        android:layout_alignParentRight="true"
        />

</RelativeLayout>
  • 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-01T07:50:34+00:00Added an answer on June 1, 2026 at 7:50 am

    If I understand correctly, single touch will not cause ACTION_POINTER_UP, but ACTION_UP. That is why it doesn’t detect the single finger. See this post for reference:
    https://stackoverflow.com/a/4269592/1084813

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

Sidebar

Related Questions

I used the following code from a previous posting to detect (most of) the
I'm using the following code to detect whether the browser being used on my
I used following code, but it displays only 2 digit of ISO country name.
i have used following code to repeat a process creation/close iteratively dim vProcessInfo as
I have used following code to create a simple PDF file. It executes fine
I am trying to used following code but I am not getting good performance
I've used following code snippet for my activity in order to deal with orientation
I've used following code for parsing XML file in c++. http://www.codeproject.com/Articles/176236/Parsing-an-XML-file-in-a-C-C-program . Now I
I used following JS code to create equal height columns: var colHeight = Math.max($('.3columngallery
I used the following code to get the path Path errorFilePath = FileSystems.getDefault().getPath(errorFile); 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.