1. Download our Official Android App: Forums for Android!

Apps onTouch and onLongClick together

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

  1. hollowback

    hollowback Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    5
    Joined:
    Nov 12, 2009

    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 Member
    Rank:
    None
    Points:
    15
    Posts:
    33
    Joined:
    Oct 19, 2009

    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 Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    5
    Joined:
    Nov 12, 2009

    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...