Solution to the GestureDetector conflict in ListView

Source: Internet
Author: User

This problem occurs when the OnGestureListener gesture slides the interface. When the interface contains ListView, the interface slide of OnGestureListener is intercepted and consumed by ListView.
To solve this problem, you need to override the OnTouchListener interface of ListView:
Java code:
 
ListView listView = (ListView) findViewById (R. id. listViewBeside );
ListView. setOnTouchListener (new View. OnTouchListener (){
@ Override www.2cto.com
Public boolean onTouch (View v, MotionEvent event ){
// TODO Auto-generated method stub
LeftPanel. getGestureDetector (). onTouchEvent (event); // you need to write it like this!
Return false;
}
});
ListView. setOnItemClickListener (new ListView. OnItemClickListener (){
@ Override
Public void onItemClick (AdapterView <?> Parent, View view,
Int position, long id ){
// TODO Auto-generated method stub
Log. I ("tag", "position =" + position );
}
});
 
Because my gesture is defined in the leftPanel View, it is leftPanel. getGestureDetector (). onTouchEvent (event );. If your gesture is written in Activity, it is mGestureDetector. onTouchEvent (event );
In this way, both the drag and the Item Click on the ListView can be ensured.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.