1. Check out our app, Forums for Android! Download and leave feedback here!

onTouch and onLongClick together

Discussion in 'Application Development' started by hollowback, Nov 12, 2009.

  1. hollowback

    hollowback Member
    Thread Starter
    5

    Nov 12, 2009
    5
    0
    5
    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
    15

    Oct 19, 2009
    33
    0
    15
    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
    Thread Starter
    5

    Nov 12, 2009
    5
    0
    5
    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...