2011-12-03 28 views
8

Extiendo mi clase desde View. y anulo la función TouchEvent. Pero, solo puedo obtener el evento ACTION_DOWN. no cualquier ACTION_UP o ACTION_MOVE. ¿Qué debería hacer para obtener esos eventos?por qué siempre recibo ACTION_DOWN desde onTouchEvent

Anulo solo en la función Toque de evento y onDraw. y no hay más que este punto de vista en la solicitud

@Override 
public boolean onTouchEvent(MotionEvent event) { 
    System.out.println("event:"+event.getAction()); 
    return super.onTouchEvent(event); 
} 
+1

Por favor, muestre su código. De lo contrario, podemos adivinar. ¡Gracias! –

Respuesta

28

Posiblemente necesita devolver true en lugar de devolver el evento super. Eso significa que manejaste ese evento, y así puedes recibir el siguiente.

1

En el trabajo teníamos un LinearLayout llamado teaser que estaba teniendo problemas similares (ha sido un tiempo). De todos modos, encontramos que este "truco" parece ayudar a obtener un poco de capacidad de respuesta adicional de un touch.

teaser.setOnTouchListener(new OnTouchListener() { 
    public boolean onTouch(View v, MotionEvent motionEvent) { 
     TransitionDrawable transition = (TransitionDrawable) v.getBackground(); 

     switch(motionEvent.getAction()) { 
      case MotionEvent.ACTION_DOWN: 
       if(transition != null) transition.startTransition(250); 
       break; 
      case MotionEvent.ACTION_UP: 
       loadArticle(position); 
      case MotionEvent.ACTION_CANCEL: 
       if(transition != null) transition.reverseTransition(0); 
       break; 
     } 
     return false; 
    } 
}); 

// Has to be here for the touch to work properly. 
teaser.setOnClickListener(null); // <-- the important part for you 

Honestamente, no pude darle ninguna rima o razón, pero espero que eso ayude.

Cuestiones relacionadas