ListView, onFling(horizontal), gesture issues

by Wall-E » Thu, 19 May 2011 02:50:58 GMT


Sponsored Links
 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;
            }



-- 



Re: ListView, onFling(horizontal), gesture issues

by Wall-E » Thu, 19 May 2011 06:07:06 GMT


 'm also noticing that in my layout that I inflate inside the
ListView, if I include a CheckBox, the behavior for the onClick for
the ListView isn't working, meaning, usually when you click/touch the
item in the ListView, it will be highlighted or change colors. When I
add a CheckBox, it doesn't highlight anymore and my
onListItemClick(...) listener never gets called. Is there a bug? or a
trick to getting this to work? If it matters, my layout is a
RelativeLayout(also tried with LinearLayout), with a CheckBox on the
far left, then a TwoLineListItem and finally an ImageView. If I just
remove the CheckBox, it will respond how a ListView normally should
respond but once I include the CheckBox it won't behave normally as
described above.

On May 18, 1:14pm, Wall-E <bashee...@gmail.com> wrote:

--


Sponsored Links


Other Threads

1. Android browser?

I've used WebView to load local html, but can't get the browser to
load a page from the web. Why are there no working examples using the
android browser?
--~--~---------~--~----~------------~-------~--~----~

2. TextView onClickListener does not work?

It seems click on TextView does not register with
TextView.setOnClickListener(listener);
listener is defined as a simple:
View.OnClickListener onClickListener = new View.OnClickListener() {
        public void onClick(View view) {
            int id = view.getId();
            Log.d(LOG_TAG, "view id: " + id);
        }
    };

the main code is simply:

@Override
    protected void onCreate(Bundle icicle) {
        super.onCreate(icicle);

        setContentView(R.layout.main);

        TextView tv = (TextView)(findViewById(R.id.tv));
        tv.setOnClickListener(onClickListener);

}

anyone has similar situation, or is there something i missed here.

thanks

--~--~---------~--~----~------------~-------~--~----~

3. Is there any type of "spacer" type widget?

4. Link Selection

5. ViewInflate.inflate is VERY SLOW

6. When I run my program, emulator runs, but program does not run

7. Android hardware performance