So I have a ListView on which I attach :
mList.setOnTouchListener(gestureListener);
What this gesture listener does is basically measure deltaX (horizontal swipe) and detects if it is higher than some value, then it knows that swipe has occured.
Then I have :
mList.setOnItemClickListener(new AdapterView.OnItemClickListener() { ... }
Which checks with gesture object if swipe has happened, if yes its a swipe, otherwise its a click.
All this works fine.
My issue is :
When I swipe elements with my thumb, sometimes I make a list scroll just a bit vertically.
The horizontal swipe is detected, but the problem is that OnItemClickListener doesnt fire, which is where I would launch some actions on the item depending if it is a swipe or not.
So the problem is that the vertical scroll mechanism of listview, makes something that makes onItemClicked event not to fire.
the list on the left works fine, no vertical scrolling appears.
the list on the right, I swipe the item but slightly to the bottom as well (still within the bounds of this item) so that the list moves just a bit. And the OnItemClicked does not fire.
How can I add a small margin for vertical scroll, so that the scroll appears but the onItemClicked is still fired?
Thanks
I was looking for implementation of swiping a listview,
now when in December edition of Gmail there is a swiping effect on each item, its implementation answers my question
It can be found here :
https://gist.github.com/2980593
Related
Simple question - how to disable recyclerview scrolling while swiping its item? I created OnTouchListener inside recyclerView item view holder, but it catches swipe events only if user makes straight horizontal line. Otherwise recycler list is scrolling. Any ideas?
I am not using ItemTouchHelper because it doesnt quite do what I want. I solved this by checking the source to it and finding the call to:
getParent().requestDisallowInterceptTouchEvent(true)
Call that when you determine the user has started swiping (i.e., moved more than a few pixels). Then don't forget it to call it again with false when the swipe is done.
I'm facing the opposite problem. If you are using the ItemTouchHelper, do this
mItemTouchHelper.startSwipe(myViewHolder);
This would force the swipe instead of the scroll.
In my android app, I have a horizontal scroll bar, and I can scroll all the way to the left and right. Go too far and you can't scroll anymore.
How can I change it that, you can keep scrolling left or right for as long as you want. Basically when u see the last thing in the horizontal scroll, then if you keep scrolling, you see the first item, and it loops like this. Similarly if you scroll to the left after seeing the first item, you see the last item.
Is this possible to do in android?
Thanks
I created a drag and drop gridview (using an OnDragListener). Grid items can be dropped upon one another. However, I also want to be able to re-order them. I implemented this, but there is a major issue left standing: the user control part.
When I drag around my shadow object I want the items to make space for my dragged object while I am dragging it around. I already implemented the moving of the other items, but I cannot seem to figure out a way to find out IF/WHEN I am in between two items. I get drag events when I hoover ABOVE an item, but not in between then. The gridview does not get any onTouchEvent calls when I am dragging, not even onInterceptTouchEvent calls.
Does anyone know a way in which I can implement this?
I already tried:
Implementing onTouchEvent and onInterceptTouchEvent in the gridview. Problem:
The gridview does not get any onTouchEvent calls when I am dragging an item, not even onInterceptTouchEvent calls.
Setting another draglistener on the whole gridview. Problem: ACTION_DRAG_LOCATION gets only called a few times, not on every move (location change), as is documented (!!).
I removed the padding between the grid items and gave the items themselfes some extra size, so that you are never inbetween items, but also on the side of one of the items. I detect when I'm at the side of an item and move the items accordingly to make space for my dragged item.
I'm trying to achieve the effect that the Google+ Android app has where there is a View that sits at the bottom of the screen, and when the user scrolls the ListView that sits behind it UP the View animates down, off screen. When the user scrolls the ListView down, even slightly, the View animates back up, on screen.
I've set up a GestureDetector, that is giving me callbacks for the scroll event on my ListView, and the callbacks are constant as I scroll so I know that part is working.
In my callback I'm trying to use the ViewPropertyAnimator to animate my y value as such:
headerView.animate().yBy(distanceY).start();
Nothing happens until I stop scrolling. Is there any way to throw this animation in with the ListView scroll on the UI thread? I get the feeling it's waiting.
I've been fighting this one also. The trick I ended up using was to replace
headerView.animate().yBy(distanceY).start();
with
headerView.setTranslationY(floatValue);
Hope this helps!
I have a ViewPager widget in every row of a ListView. This provides a shelf-like UI, so the user can scroll around searching for a shelf vertically, and then scroll horizontally amongst the contents of a shelf. This works.
But the scrolling experience is terrible: if I start to drag a shelf's ViewPager, scroll it horizontally, and accidentally drag a bit upwards/downwards, then the ListView "traps" this dragging action, and start to scroll vertically, ending my horizontal drag. In this state, the drag action won't "return" to the ViewPager, the ListView has it, and that's it. I have to start another drag action to affect the ViewPager again. So I guess the ListView has precedence in these cases.
How can this be fixed? I'd like to achieve the exact opposite: If the ViewPager inside a list row starts reacting to a horizontal drag, then it should trap that action, and this drag should stop affecting the ListView, no matter how the user moves his/her finger vertically. Can this be done?
I've found a solution in this thread. There the problem is to handle touch events properly for a HorizontalScrollView inside a regular ScrollView, but the solution to that problem seems to apply to this one too.