attribute android listview gesture swipe ontouchlistener

android - attribute - title en css



¿Cómo implementar tanto onuch como también en vuelo en una misma vista de lista? (2)

Pseudo código de respuesta para aclarar los comentarios anteriores. Cómo tener el método onTouch de MySimpleGestureListener llamado.

public class GestureExample extends Activity { protected MyGestureListener myGestureListener; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); myGestureListener = new MyGestureListener(this); // or if you have already created a Gesture Detector. // myGestureListener = new MyGestureListener(this, getExistingGestureDetector()); // Example of setting listener. The onTouchEvent will now be called on your listener ((ListView)findViewById(R.id.ListView)).setOnTouchListener(myGestureListener); } @Override public boolean onTouchEvent(MotionEvent event) { // or implement in activity or component. When your not assigning to a child component. return myGestureListener.getDetector().onTouchEvent(event); } class MyGestureListener extends SimpleOnGestureListener implements OnTouchListener { Context context; GestureDetector gDetector; public MyGestureListener() { super(); } public MyGestureListener(Context context) { this(context, null); } public MyGestureListener(Context context, GestureDetector gDetector) { if(gDetector == null) gDetector = new GestureDetector(context, this); this.context = context; this.gDetector = gDetector; } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return super.onFling(e1, e2, velocityX, velocityY); } @Override public boolean onSingleTapConfirmed(MotionEvent e) { return super.onSingleTapConfirmed(e); } public boolean onTouch(View v, MotionEvent event) { // Within the MyGestureListener class you can now manage the event.getAction() codes. // Note that we are now calling the gesture Detectors onTouchEvent. And given we''ve set this class as the GestureDetectors listener // the onFling, onSingleTap etc methods will be executed. return gDetector.onTouchEvent(event); } public GestureDetector getDetector() { return gDetector; } } }

Tengo una vista de lista e implementado onclick y también onfling.problem es cuando hago fling (deslizar de izquierda a derecha), el evento onclick de listview también se está ejecutando. ¿Cómo superar este problema? ¿Cómo diferenciar el toque (toque) y el lanzamiento (deslizar) en la vista de lista?

listClickListener = new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View v,int position, long id) { //Job of Onclick Listener } }; mContactList.setOnItemClickListener(listClickListener); mContactList.setAdapter(adapter); // Gesture detection gestureDetector = new GestureDetector(new MyGestureDetector(prosNos)); gestureListener = new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { if (gestureDetector.onTouchEvent(event)) { return true; } return false; } }; mContactList.setOnTouchListener(gestureListener); } public class MyGestureDetector extends SimpleOnGestureListener { @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { // My fling event return false; } }

PS es posible? comentar el OnClickListener de ListView y escribir la misma lógica en cualquier onTouchEvent? pero todavía no tengo ninguna duda de que onFling llamará a toTouch. Estoy en lo cierto?


Atrapa el evento Multi Click

Resuelvo este problema de esta manera, es bastante simple!

Object.setOnTouchListener( new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent event) { int action = event.getActionMasked(); switch (action) { case MotionEvent.ACTION_DOWN: // button press initialX = event.getX(); initialY = event.getY(); break; case MotionEvent.ACTION_UP: //button release float finalX = event.getX(); float finalY = event.getY(); if (initialX > finalX) { //Right to Left swipe performed } if (initialX < finalX) { //Left to Right swipe performed } if (initialY < finalY) { //Log.d( TAG, "Up to Down swipe performed" ); } if (initialY > finalY) { //Log.d( TAG, "Down to Up swipe performed" ); } break; case MotionEvent.ACTION_CANCEL: Log.d( TAG, "Action was CANCEL" ); break; case MotionEvent.ACTION_OUTSIDE: Log.d( TAG, "Movement occurred outside bounds of current screen element" ); break; case MotionEvent.ACTION_MOVE: Toast.makeText(getApplicationContext(), "Action was MOVE",Toast.LENGTH_SHORT ).show(); break; } return true; } } );