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

The Archive Base Latest Questions

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

my program creates expandable Lists, and I have implemented swipes- but I cant figure

  • 0

my program creates expandable Lists, and I have implemented swipes- but I cant figure out how to add double taps.

Firstly, I have list= getExpandableListView();

within my main class, I implemented swipes using the following code:

final ActivitySwipeDetector swipeDetector = new ActivitySwipeDetector();


         list.setOnTouchListener(swipeDetector);

         list.setOnItemClickListener(new OnItemClickListener() {

                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                        if (swipeDetector.swipeDetected()){
                            // do the onSwipe action 
                        } else {
                            // do the onItemClick action
                        }
                    }
                                });


            list.setOnItemLongClickListener(new OnItemLongClickListener() {
                public boolean onItemLongClick(AdapterView<?> parent, View view,int position, long id) {
                    if (swipeDetector.swipeDetected()){
                        // do the onSwipe action
                        return true;
                    } else {
                        // do the onItemLongClick action
                        return false;
                    }
                }
            });

And I made a class that is my Swipe detector:

public class ActivitySwipeDetector implements View.OnTouchListener {

public static enum Action {
    LR, // Left to Right
    RL, // Right to Left
    TB, // Top to bottom
    BT, // Bottom to Top
    None // when no action was detected
}


private static final String logTag = "SwipeDetector";
private static final int MIN_DISTANCE = 100;
private float downX, downY, upX, upY;
private Action mSwipeDetected = Action.None;


public boolean swipeDetected(){
    return mSwipeDetected != Action.None;
}

public Action getAction(){
    return mSwipeDetected;
}



public boolean onTouch(View v, MotionEvent event) {
    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN: {
        downX = event.getX();
        downY = event.getY();
        mSwipeDetected = Action.None;
        return false; // allow other events like Click to be processed
    }
    case MotionEvent.ACTION_UP: {
        upX = event.getX();
        upY = event.getY();

        float deltaX = downX - upX;
        float deltaY = downY - upY;

        // horizontal swipe detection
                if (Math.abs(deltaX) > MIN_DISTANCE) {
                    // left or right
                    if (deltaX < 0) {
                        Log.i(logTag, "Swipe Left to Right");
                        mSwipeDetected = Action.LR;
                        return false;
                    }
                    if (deltaX > 0) {
                        Log.i(logTag, "Swipe Right to Left");
                        mSwipeDetected = Action.RL;
                        return false;
                    }
                } else 

                // vertical swipe detection
                if (Math.abs(deltaY) > MIN_DISTANCE) {
                    // top or down
                    if (deltaY < 0) {
                        Log.i(logTag, "Swipe Top to Bottom");
                        mSwipeDetected = Action.TB;
                        return false;
                    }
                    if (deltaY > 0) {
                        Log.i(logTag, "Swipe Bottom to Top");
                        mSwipeDetected = Action.BT;
                        return false;
                    }
                } 
                return false;
    }
    }
    return false;
}

}

What do I add to make the program detect Double Taps?
I have tried to add the following to my swipe class:

 public boolean onDoubleTap(MotionEvent e) {
    float x = e.getX();
    float y = e.getY();

    Log.d("Double Tap", "Tapped at: (" + x + "," + y + ")");

    return true;
}

but Im not sure how to add the listener for it in the main class..

This just gives me errors on the “list.setOnDoubleTapListener” and “new onDoubleTapListener”..

list.setOnDoubleTapListener(new OnDoubleTapListener(){ 
                public boolean onDoubleTap(MotionEvent e) { 

                     return false; 
                } 
                public boolean onDoubleTapEvent(MotionEvent e) { 
                    // viewA.setText("-" + "onDoubleTapEvent" + "-"); 
                     return false; 
                } 
                public boolean onSingleTapConfirmed(MotionEvent e) { 
                     //viewA.setText("-" + "onSingleTapConfirmed" + "-"); 
                     return false; 
                } 

         });

Please Help

Z.

  • 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:44:31+00:00Added an answer on June 1, 2026 at 1:44 am

    The solution to the above problem:

    Added the following to the swipe detector class:private static final int MIN_DISTANCE = 100;
    private float downX, downY, upX, upY;
    private Action mSwipeDetected = Action.None;
    private long lastTouchTime = -1;

    Added this to the ActionDown

     case MotionEvent.ACTION_DOWN: {
    
            downX = event.getX();
            downY = event.getY();
            mSwipeDetected = Action.None;
    
    
            long thisTime = System.currentTimeMillis();
    
            if (thisTime - lastTouchTime < 250) {
    
               // Double click
             //  p = mapView.getProjection().fromPixels((int) e.getX(), (int) e.getY());
               lastTouchTime = -1;
               Log.i(logTag, "DOUBLE TAP");
            } else {
               // too slow
               lastTouchTime = thisTime;
            }
    
    
             return false; // allow other events like Click to be processed
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program that creates semaphore. But when i try to use SETALL,
I have made a program that scans rss feeds. This same program creates feeds
In Form1 I have PageControl. At run time my program creates tab sheets. In
use this website a lot but first time posting. My program creates a number
I have a program that creates a Windows user account using the NetUserAdd() API
I have a program that creates a JFrame and makes it visible. Is there
I have a program that creates a small file in the Bin directory for
I have an AppleScript program which creates XML tags and elements within an Adobe
I have a program that creates a html file as standard output. To view
I have a program which creates DialogBox window when user clicks the menu item

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.