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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:53:19+00:00 2026-05-18T03:53:19+00:00

i have a listview and implemented onclick and also onfling.problem is when i do

  • 0

i have a listview and implemented onclick and also onfling.problem is when i do fling(swipe left to right), onclick event of listview is also getting executed.How to overCome this problem? how to differentiate touch(tap) and fling(swipe) in listview?

     listClickListener = new OnItemClickListener() {

           public void onItemClick(AdapterView<?> parent, View v,int position, long id) {
            //Job of Onclick Listener     
           }
      };
       mContactList.setOnItemClickListener(listClickListener); 
        mContactList.setAdapter(adapter);
        // Gesture detection 
        gestureDetector = new GestureDetector(new MyGestureDetector(prosNos)); 
         gestureListener = new View.OnTouchListener() { 
             public boolean onTouch(View v, MotionEvent event) { 
                 if (gestureDetector.onTouchEvent(event)) { 
                     return true; 
                 } 
                 return false; 
             } 
         }; 

         mContactList.setOnTouchListener(gestureListener); 

        }

     public class MyGestureDetector extends SimpleOnGestureListener { 

        @Override 
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { 
           // My fling event
           return false;
        }
    }

P.S. Is it possible? to comment the OnClickListener of ListView and writing the same logic in any onTouchEvent? but still I have no doubt that onFling will call onTouch. Am I right?

  • 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-18T03:53:19+00:00Added an answer on May 18, 2026 at 3:53 am

    Pseudo code answer to clarify the above comments. How to have the MySimpleGestureListener’s onTouch method called.

    public class GestureExample extends Activity {
    
        protected MyGestureListener myGestureListener;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
    
            super.onCreate(savedInstanceState);
    
            myGestureListener = new MyGestureListener(this);
            // or if you have already created a Gesture Detector.
            //   myGestureListener = new MyGestureListener(this, getExistingGestureDetector());
    
    
            // Example of setting listener. The onTouchEvent will now be called on your listener
            ((ListView)findViewById(R.id.ListView)).setOnTouchListener(myGestureListener);
    
    
        }
    
    
        @Override
        public boolean onTouchEvent(MotionEvent event) {
            // or implement in activity or component. When your not assigning to a child component.
            return myGestureListener.getDetector().onTouchEvent(event); 
        }
    
    
        class MyGestureListener extends SimpleOnGestureListener implements OnTouchListener
        {
            Context context;
            GestureDetector gDetector;
    
            public MyGestureListener()
            {
                super();
            }
    
            public MyGestureListener(Context context) {
                this(context, null);
            }
    
            public MyGestureListener(Context context, GestureDetector gDetector) {
    
                if(gDetector == null)
                    gDetector = new GestureDetector(context, this);
    
                this.context = context;
                this.gDetector = gDetector;
            }
    
    
            @Override
            public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
    
                return super.onFling(e1, e2, velocityX, velocityY);
            }
    
            @Override
            public boolean onSingleTapConfirmed(MotionEvent e) {
    
                return super.onSingleTapConfirmed(e);
            }
    
    
    
    
    
            public boolean onTouch(View v, MotionEvent event) {
    
                // Within the MyGestureListener class you can now manage the event.getAction() codes.
    
                // Note that we are now calling the gesture Detectors onTouchEvent. And given we've set this class as the GestureDetectors listener 
                // the onFling, onSingleTap etc methods will be executed.
                return gDetector.onTouchEvent(event);
            }
    
    
            public GestureDetector getDetector()
            {
                return gDetector;
            }       
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have found this example Lazy load of images in ListView from Fedor which
I have a ListView with let's say 5 items. When I click on one
I have a ListView with different layouts for different items. Some items are separators.
I have a listview from an SQLDatabase using custom CursorAdaptor. I would like to
I have a ListView with a CheckBox as one of the columns, bound to
I have a ListView that contains a large collection of rows with textboxes that
When overriding the baseadapter on an android listview, you have to implement this method
Scenario: A ListView is DataBound to an ObservableCollection<CustomClass> and is displaying it's items through
I have just written a Word Document creation web application using .NET 3.5 which
I have this query and its result implements IEnumerable . RoutesEntities routesModel = new

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.