Cannot adjust seekbar value with swipe gesture in RecyclerView - android

I created a RecyclerView with "swap item positions" and "remove item with swipe gesture" as explained here. Everything works fine except for a seek bar which is contained in the items. I can only adjust the seekbar value by tapping on some spot but not changing the value by tapping on the draggable thumb and then moving it left or right. What happens in those cases is that the swipe gesture removes the item from the parent RecyclerView.
How can I achieve to change the value of the seekbar when a swipe gesture occurs on it and only remove it when a swipe gesture is performed outside the seekbar?

#Ben P.: I created my own class that extends from LinearLayout, implemented the onInterceptTouchEvent but I was not able to interrupt the swipe gesture. I guess because I would have needed to intercept the RecyclerView method, however, this class does not provide an onInterceptTouchEvent method which could be overridden.
Instead, I solved my problem as follows: I have two types of views I display in the RecyclerView (default and edit) and only the edit type contains a SeekBar. As it is absolutely okay to not allow to remove the currently-edited item, I distuingished the type of the ViewHolder in the getMovementFlags method which I override from ItemTouchHelper.Callback().
(Sorry that I didn't mention the piece of information with the two view types.)

Related

Make a listview programmatically selectable only

I have a Listview in a Fragment, and when I click an item a new Fragment is shown.
The problem is that for few milliseconds i can see the item selected by the touch. Is there a way to make these Listview programmatically selectable only? For example when I return to the Fragment and something connected is running (i already know how to select an item in Java, i just need to know how to disable touch clicks).
The item is colored with a selector and the Listviews are set to choice mode single.
One way to do it would be to implement the ontouchListener() of the fragment, and rewrite the onTouch() method with a simple:
return false
to consume the event.
You can achieve this quite easily. The two ways that are on top of my head are :
Disable touch on the list.
Put your ListView in a RelativeLayout (rootLayout) in the RelativeLayout(rootLayout) first item should be your ListView and the second can be another RelativeLayout(coverLyt) with height and width set as match_parent and clickable set to true. This will make the coverLyt take the touch events instead of your ListView. When you want the listView touch events to work set coverLyt's visibility to gone and visible when vice versa.

Recyclerview - how to disable vertical scrolling on item swipe (fling)

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.

Dispatch TouchEvent to Listview after it's intercepted by parent

I have a layout which looks something like this:
Inside the ViewPager are a number of Fragments, of which each holds a ListView.
Now I want to do this:
By scrolling down, the ListView mustn't scroll. Instead the header has to be transformed so it looks like a native ActionBar.
I'm doing this by intercepting the TouchEvent in the root layout of my activity.
I have overwritten the onInterceptTouchEvent() method of my parent layout and check if a TouchEvent should be intercepted or not, by retrieving the current visible ListView and check if the firstVisibleItem is the first and it's completely visible.
If the TouchEvent should be intercepted, my custom OnGesutreListener's onScroll() method is called. So the "animation" progress depends on the scroll offset.
All that works really fine. But now here's my problem:
The transformation is ready and the user still scrolls down. As a user i would expect the ListView to scroll down. But the TouchEvent isn't dispatched to the ListView because it's still intercepted by the parent layout. Only after moving the finger up and down again onInterceptTouchEvent is called again (now the parent layout hasn't to intercept) and the list is scrollable.
I tried a few things but they didn't work out for me:
I tried to call my listView's onTouchEvent manually in the
onTouchEvent() method of my parent's layout - noting happens
I tried to call my listView's onTouchEvent manually in my onScroll method,
also this didn't worked out.
Maybe some of you have a clue how to work this out.
Thanks a lot and greetz!
Could you try getting the x position moved by the finger in the parent onTouchEvent and then using
listView.smoothScrollByOffset(int offset);
To scroll the list view?
Edit: Based on feedback it should be:
smoothScrollBy((int) distanceY, 1);
Thanks to MungoRae's answer I could figure it out (please give him an upvote!)
listView.smoothScrollBy(int offset, int durationInMillis)
this works fine for me. The offset is the scrolled distanceY and the duration is set to 1 msec
You can use View.requestDisallowInterceptTouchEvent(). It will enable and disable the ability of a view to intercept touch event.
set requestDisallowInterceptTouchEvent(true) on the parent layout while touching , it will enable the listview to handle the touch event.

android drag and drop gridview ordering

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.

Android ListActivity Clicks

I have a ListActivity as my main activity. I want to be able to do a few things on a single item in the list i.e.
Longpress to bring up a contextmenu for that item
Swipe left to right to slide a new screen from the right to edit the list item.
Does anyone have any code they can show me that does this?
Longpress to bring up a contextmenu for that item
See here for how to use context menus. Here is a sample project that demonstrates their use.
Swipe left to right to slide a new screen from the right to edit the list item.
See here for how to use gesture libraries. Here is a ViewSwiper that adds gestures to a ViewFlipper. Here is an implementation of a drag-and-drop ListView, based on some poorly-understood code culled from Android itself. Blending all of that together, you may be able to implement what you seek. However, this will be rather difficult, and may not result in a user interface that is very usable. I strongly encourage you to simply have list item clicks be the way to indicate to edit an item, not a gesture.
I think You can use a 2 Child ViewFlipper as your Listitem.
one child for a normal dispaly(a TextView maybe), another a EditText.
and in case it work as you said, don't forget to set gesterListener on your ViewFlipper,do showNext or showPrevious in your OnFling method.

Categories

Resources