So I have a listview using an arrayadapter.  I want to detect a
horizontal swipe/fling to toggle a view item to gone/visible inside
the listview.  What I've done to achieve this is to have a
SimpleGestureDetector to detect the fling.  I've added an
onTouchListener to the listview that returns if a fling/swipe was
detected.  If a swipe was detected, I set that view to either visible
or gone.  Now this works for the first item in my listview but not for
the others.  Inside of the onTouch method I have access to a View in
which I access my layout items. Also, the listview gets distorted and
does not refresh correctly.  I even call invalidate on the listview
after I've done the change.  So first off, am I going about this
correctly or is there a better/proper method to accomplish what I'm
trying to do?

Here is some of my code:

        gestureListener = new View.OnTouchListener()
        {
            public boolean onTouch(View v, MotionEvent event)
            {
                if(gestureDetector.onTouchEvent(event))
                {
                        ImageView deleteImageView = (ImageView)
v.findViewById(R.id.deleteSourceImageView);
                        if(deleteImageView.getVisibility() == View.GONE)
                        {
                                deleteImageView.setVisibility(View.VISIBLE);
                        }
                        else
                        {
                                deleteImageView.setVisibility(View.GONE);
                        }
                        dataListView.invalidate();
                    return true;
                }
                return false;
            }
        };


        class MyGestureDetector extends SimpleOnGestureListener
        {
            @Override
            public boolean onFling(MotionEvent e1, MotionEvent e2, float
velocityX, float velocityY)
            {
                try
                {
                if (Math.abs(e1.getY() - e2.getY()) >
SWIPE_MAX_OFF_PATH)
                {
                    return false;
                }
                // right to left swipe
                if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE &&
Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY)
                {
                        return true;
                }
                else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE &&
Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY)
                {
                        return true;
                }
            }
                catch (Exception e)
            {
                // nothing
                        return false;
            }
                return false;
            }



-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to