Trouble with detecting gestures over ListView?

Just to throw in a completely different answer with a completely different approach.

Just to throw in a completely different answer with a completely different approach... I've made a custom view called SwipeView, it's open source etc etc blah blah blah. It should let you do what you want to do as simply as going: mSwipeView. AddChild(myList1); mSwipeView.

AddChild(myList2); You won't have to mess about with gesture detectors or anything, and the the swipe should follow your finger as you do it... (This reads like a terrible terrible advert, please excuse me. It's been a long day ;) Have some wonderful links: jasonfry.co.uk/?id=23 jasonfry.co.uk/?id=24 http://jasonfry.co.uk/?id=28.

This is similar to a component I recently developed, except that I added view recycling to mine and its backed by a listAdapter. Basically, I kanged a bunch of ListView code and attached it to a custom gesture driven HorizontalScrollView as you did. – jfelectron Jan 20 at 9:04 Yeah I'm working on adding that to SwipeView too!

Also, I just (literally just, about 2 minutes ago) noticed that there is a bug with ListViews on a SwipeView. I have now fixed the bug and updated the git repo. Github.Com/fry15/uk.co.jasonfry.android.

Tools – fry15 Jan 20 at 12:14 3 jfelectron is yours on GIThub though? – Ben Collier Jan 20 at 18:57.

EDITScratch that, totally wrong. I think you would have to update this part, and detect if you were scrolling left or right, and return true if you were in a swiping state. Or at least that is where I would look first.

MGestureListener = new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { if (mGestureDetector. OnTouchEvent(event)) { return true; } return false; } }; Continuing with my poor example, sorry. Within the onTouch I believe you can test the event.getAction() and determine if a long click has occured.

If it has, and your in a flinging motion, then return true as to capture the long click. Afraid this is more of a suggestion than a definitive answer. Also have you check the other onmethods that you can override from the SimpleOnGestureListener.

Just checked and @Override public void onLongPress(MotionEvent e) { // TODO Auto-generated method stub super. OnLongPress(e); } might be something you could experiment with.

That's what is happening. Or is your example what your EDIT is intending to invalidate? – Andrew Jan 13 at 22:43 Sorry, its a terrible example, been fixing another issue.

Will try and explain better later. – Emile Jan 14 at 3:22.

Since you're using a GestureDetector, the thing to do is implement SimpleGestureDetector. OnLongPress(MotionEvent e) for handling long clicks. However, you can't know the listitem that's been long-pressed from there, so you need to remember it from the normal onItemLongClick().

Class MyGestureDetector extends SimpleOnGestureListener { ... @Override public void onLongPress(MotionEvent e) { if (longClickedItem! = -1) { Toast. MakeText(MainActivity.

This, "Long click! ", Toast. LENGTH_LONG).show(); } } } int longClickedItem = -1; @Override public boolean onItemLongClick(AdapterView list, View view, int position, long id) { longClickedItem = position; return true; } @Override public boolean onTouchEvent(MotionEvent event) { // Reset longclick item if new touch is starting if (event.getAction()==MotionEvent.

ACTION_DOWN) { longClickedItem = -1; } if (mGestureDetector. OnTouchEvent(event)) return true; else return false; } I have tested this and it seems to work fine.

Thank you for your response. I will give it a try. I should note that while a long press is what is being activated and is what I've noted, what I'd really like to happen is have no gesture leak if someone is swiping.

There are a few other issues, especially with Android phones that can do the iPhone end-of-list animations and such. The real problem here is that swiping is sending other gestures to the list; and I don't know how to stop that. – Andrew Jan 17 at 21:24 I've just tried this and it does prevent the long click from executing when I swipe, though the item your finger originates on does highlight yellow; so some piece of the gesture is obviously leaking to the list – Andrew Jan 17 at 21:31 Try calling list.cancelLongPress() if the gesture detector returns true... – Reuben Scratton Jan 18 at 10:45.

Go you your gestureDetector and set mGestureDetector. SetIsLongpressEnabled(false); This will prevent long press events from being detected.

I developed a custom component derived from horizontalScrollView that does this. I have listViews as the child views and swipe without long-presses. It backed by a listAdapter, which could be anything you want (ArrayAdapter, CursorAdapter...).

It loads up to three child views and then on flipping, just swaps them on either side. Most of this is kanged from ListView and needs to be refactored. Its way too long to post here directly.

pastie.org/1480091.

Just to throw in a completely different answer with a completely different approach...

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions