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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:56:46+00:00 2026-06-01T01:56:46+00:00

I’m looking for a way to implement drag and drop with multi touch in

  • 0

I’m looking for a way to implement drag and drop with multi touch in my application.
I have many views and I want that a first user drag a view in the same time than a second user is dragging an other view.

My single touch drag and drop works well, here is a part of my code (my views are implementing this listener. onDragStart records the point touched, onDragContinuing change the position of the view and onDrop check if the position is valid) :

public boolean onTouch(View v, MotionEvent event) {

    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        return onDragStart(event.getX(), event.getY());
    }

    else if (event.getAction() == MotionEvent.ACTION_MOVE){
        return onDragContinuing(event.getRawX(), event.getRawY());                      
    }

    else if (event.getAction() == MotionEvent.ACTION_UP){
        return onDrop(event.getRawX(), event.getRawY());
    }

    else{
        return false;
    }

}

I have tried to implement the multitouch like that, but it doesn’t works :

private static final int INVALID_POINTER_ID = -1;
// The ‘active pointer’ is the one currently moving our object.
private int mActivePointerId = INVALID_POINTER_ID;

public boolean onTouch(View v, MotionEvent event) {

    int action = event.getAction();
    int actionCode = action & MotionEvent.ACTION_MASK;

    switch(actionCode){

        case MotionEvent.ACTION_DOWN :{
            Toast.makeText(getContext(), "down", Toast.LENGTH_SHORT).show();
            // Save the ID of this pointer
            mActivePointerId = event.getPointerId(0);
            return onDragStart(event.getX(), event.getY());
        }

        case MotionEvent.ACTION_POINTER_DOWN :{
            Toast.makeText(getContext(), "pointer down", Toast.LENGTH_SHORT).show();
            // Save the ID of this pointer
            // Extract the index of the pointer that left the touch sensor
            final int pointerIndex = (action & MotionEvent.ACTION_POINTER_ID_MASK) >> MotionEvent.ACTION_POINTER_ID_SHIFT;
            mActivePointerId = event.getPointerId(pointerIndex);
            return onDragStart(event.getX(mActivePointerId), event.getY(mActivePointerId));
        }

        case MotionEvent.ACTION_MOVE :{
            Toast.makeText(getContext(), "move", Toast.LENGTH_SHORT).show();
            final int pointerIndex = (action & MotionEvent.ACTION_POINTER_ID_MASK) >> MotionEvent.ACTION_POINTER_ID_SHIFT;
            final int mCurrentPointerId = event.getPointerId(pointerIndex);
            if (mActivePointerId == mCurrentPointerId){
                return onDragContinuing(getRawX(event, mActivePointerId), getRawY(event, mActivePointerId));
            }
            else return false;
        }

        case MotionEvent.ACTION_UP :{
            Toast.makeText(getContext(), "up", Toast.LENGTH_SHORT).show();
            final int pointerIndex = (action & MotionEvent.ACTION_POINTER_ID_MASK) >> MotionEvent.ACTION_POINTER_ID_SHIFT;
            final int mCurrentPointerId = event.getPointerId(pointerIndex);

            if (mActivePointerId == mCurrentPointerId){
                return onDrop(event.getRawX(), event.getRawY());
            }
            else return false;

        }

        case MotionEvent.ACTION_POINTER_UP :{
            Toast.makeText(getContext(), "pointer up", Toast.LENGTH_SHORT).show();
            final int pointerIndex = (action & MotionEvent.ACTION_POINTER_ID_MASK) >> MotionEvent.ACTION_POINTER_ID_SHIFT;
            final int mCurrentPointerId = event.getPointerId(pointerIndex);

            if (mActivePointerId == mCurrentPointerId){
                return onDrop(getRawX(event, pointerIndex), getRawY(event, pointerIndex));
            }
            else return false;

        }

        default :{
            return false;
        }

    }

}

/**
 * MotionEvent has no getRawX(int) method; simulate it pending future API approval. 
 */
private static float getRawX(MotionEvent event, int pointerIndex) {
    float offset = event.getX() - event.getRawX();
    return event.getX(pointerIndex) + offset;
}

/**
 * MotionEvent has no getRawY(int) method; simulate it pending future API approval. 
 */
private static float getRawY(MotionEvent event, int pointerIndex) {
    float offset = event.getY() - event.getRawY();
    return event.getY(pointerIndex) + offset;
}

What’s wrong ? Can you help me ? Thanks you !

  • 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-01T01:56:48+00:00Added an answer on June 1, 2026 at 1:56 am

    I’ve found the solution and the explanation.

    Android doesn’t support multi-touch in multi views, the multi-touch is only for one view. So, to have a multi-touch for multi view, we had to catch touch event in the main activity and generate new event for child views.

    Thanks to Pascal Welsch and his blog ( http://www.passsy.de/multitouch-for-all-views/ ), and a modification of a mistake in his code that I’ve found ( http://code.google.com/p/friendbattle/issues/detail?id=19 ), I have solved my problem.

    Hope this will help for other people 🙂

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I have a jquery bug and I've been looking for hours now, I can't
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

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.