onTouch and onLongClick together


Last Updated:

  1. hollowback

    hollowback Member This Topic's Starter

    Joined:
    Nov 12, 2009
    Messages:
    5
    Likes Received:
    0
    Hi, I've got problem with using onTouch and onLongClick events together. My code looks like that:
    Code (Text):
    1.  
    2. SurfaceView sv = (SurfaceView)findViewById(...);
    3. sv.setOnLongClickListener(new OnLongClickListener() {        
    4.          @Override
    5.          public boolean onLongClick(View v) {
    6.                                 /* ... */
    7.             return true;
    8.          }
    9.       });  
    10. sv.setOnTouchListener(new OnTouchListener() {
    11.          @Override
    12.          public boolean onTouch(View v, MotionEvent event) {
    13.             /* ... */
    14.             return true;
    15.          }
    16.       });  
    But only onTouch event is proceeded. Is there any solution, how to use this two events together, or to detect longClick in onTouch event?
     

    Advertisement
  2. metter

    metter Active Member

    Joined:
    Oct 19, 2009
    Messages:
    33
    Likes Received:
    0
    Hey hollowback

    Return false, not true. If you return true you are saying that you have consumed the event and it will then be discarded.

    Note: Actually I am wondering about that. This behaviour seems to be wrong as it is not the same kind of event...But maybe there's a reason for this? Anyone?


    Update: It's explained here: http://developer.android.com/guide/topics/ui/ui-events.html

    Cheers.
     
  3. hollowback

    hollowback Member This Topic's Starter

    Joined:
    Nov 12, 2009
    Messages:
    5
    Likes Received:
    0
    Thank you. I tryied to return false in onLongClick event, but it didn't solve it. If I return false in onTouch event, everything works like charm :)
     

Share This Page

Loading...