Properly exchange items between multiples RecyclerViews - android

Being objective, my goal is simple (or not), drag a recycler's item to other one in my activity.
The scenario is the following.
I have a list of items, let's call them sections, and inside a section another list of items, of another type, the elements.
I want exchange the elements between the sections. The list of sections isn't fixed, can be changed adding and removing a section, but hasn't any movement behavior. The elements also can be added and removed from a section, but have this reorder approach.
I've found some strategies with fixed "section". Here is an example. This one uses drag and drop to make the exchange. But it's too simple. For example, don't consider the need to scroll recycle when the dragging reaches bottom or top of visible elements. That's because it has only two lists. Does Drag and Drop have this behavior, forcing the scroll?
Is there any way to do this using the ItemTouchHelper? If so, how would it be? ItemTouchHelper seems better, 'cause considers the scroll problem and has a more intuitive reorder animation.
If you think of a better approach than using recyclers, feel free to indicate such strategy to me.

You use drag and drop for the dragging and dropping, the scrolling and such you'd have to make yourself using the appropriate events in the OnDragListener.

Related

How can I make recyclerview scroll by only one direction and disable others

I just want to allow only scroll left in horizontal recyclerview for example. Please help me on that
Best way is to remove other directions item from adapter, which are getting hidden one by one. So when user scroll back ward it will not show up any thing.
I would not touch the data in your adapter (what does the data have to do with a UI business rule?). If you want, you could notify your Repository or ViewModel what views have been "scrolled" but that's a lot of events going up, and state coming down for everyone involved.
You have the tools at your disposal in the form of a combination of:
A GestureDetector (See (the documentation.)
A TouchListener (See (the documentation.)
Your favorite search engine to put these things together.
or perhaps benefit from the somewhat modular approach of RecyclerView:
Using OnItemTouchListener and a OnScrollListener to analyze the events and ignore the ones you don't want.
You could also create your own extended RecyclerView but that's more painful because you now need to change it all over the place you want this behavior.
In any case, your search engine of choice is also a good starting point. But think of this as:
You will need to intercept the touches and flings gestures (as well as other motion actions like "Dpads" and other Accessibility Events that may trigger a "scroll", evaluate in which direction this is headed, and determine if you still want that event to happen.

Overwhelmed by layouts, what are my alternatives to make a layout like this, but dynamic number of items?

I'm a flutter user trying out kotlin dev first time, but im kinda confused what the best alternatives for this type of layouts are.
I understand that I use recyclerview for a dynamic number of items. And since theres two dynamic ones (one for number of sets, one for each exercise). Do I use two nested recyclerviews?
It really depends what you're doing here. A RecyclerView is basically a list, so it's a good choice for a scrollable set of items - which it looks like your Exercises are. But how do you want to display those weights?
It's possible to make them scrollable, so some of them aren't visible on the screen (the categories on the Play Store act like this). For that you would need a nested scrolling view of some kind - could be a horizontal RecyclerView, or it could just be a ScrollView wrapped around a LinearLayout you throw views into.
But the other option you might want, is that for each Exercise, all of its weights are visible in a grid of some kind. No scrolling, all there up-front to see and poke at. So the first question is which of those do you want?
I'd assume it's this version - where you can easily visualise the contents - in which case you're not talking about nested lists, it's just one list, and each item contains a grid you can add things too. For that setup, there's GridLayout, TableLayout, and ConstraintLayout Flow (which acts like FlexBox if you're familiar with that). So in the layout for an item in your list, you have a container for stuff, and you put the stuff in it, and the container expands vertically as needed

Android: How can I create a RecyclerView where I can freely drag and drop an item to do certain things?

I am facing a tricky task where I have a horizontal RecyclerView where the user should be able to grab the first item and freely move it. If he drops it in two certain areas, it will be added into the other two lists respectively.
Here is a diagram for the explicit task:
Basically the user can only grab the first item and then choose to drop it inside favourite list or add it in the disliked list. The move should be 100% free and follow the user's finger on the screen. If the item gets dropped halfway between the original middle list and one of the top or bottom list, but closer to the result list, the item should then have a smooth animation towards the other list with some sort of interpolation [This is an important part, the animation should be very smooth to the point that the card gets on the final position].
I have never done anything like it, only have a little experience with MotionLayout but I know that's not of use in this example. At first glance, I expect that this can be done with DragEvents but I have no idea where to start. Any help or examples to teach me how to do this?
Could you please take a look on https://github.com/davideas/FlexibleAdapter
Fast and versatile Adapter for RecyclerView which regroups several features into one library to considerably improve the user experience

RecyclerView vs ViewPager

Currently, I am exploring the option of displaying data from a database by swiping left to right and also allowing users add and remove data from any position in the data array.
I found out that there are 2 possible solutions to do this. One is a RecyclerView with horizontal scroll and the other is a ViewPager with a FragmentStatePagerAdapter .
Which is more efficient? In terms of Memory usage and Ease of implementation?
Thanks.
I would say they are comparable in terms of memory usage and ease of implementation. Where they differ most is in the interaction they provide to the user.
ViewPager is designed to show one item at a time. The visible item takes up full width of the ViewPager. You can only swipe one item at a time and scrolling always snaps to showing one item in the centre – you're never left in an in-between position partially showing two items.
RecyclerView with a horizontal layout manager on the other hand can have items of any width – you could be showing many items at once or you could have items wider that RecyclerView's width or you could match their widths to mimic ViewPager. You can freely scroll – you are not limited to one item width or RecyclerView's width, you can do a fling gesture to scroll big distances. And there's no snapping – when the scroll finishes there's no aligning items to the centre or any of the sides.
As you see there are a few differences. I would recommend you to choose your widget based on the UI you want to achieve. If you want ViewPager's behaviour (one item visible at a time, swipe limited to one item and snapping to show the full item) then go with a ViewPager. It's possible but not trivial to replicate this behaviour using a RecycleView. I would definitely say it is way more difficult to use RecyclerView if you want to make it behave like ViewPager. Conversely it's pretty much impossible to customise ViewPager's behaviour, so if that's not what you want then you definitely should use a RecyclerView.
In term of ease of implementation (this is just my own opinion),
ViewPager is good for displaying the list of data that is not required often add and remove since PagerAdapter can't notify each specific item that it is removed or added it can only call notifyDataSetChanged() which notify that all set of data has been changed. Therefore, it is hard to handle the animation when the item is added or removed.
While in RecyclerView, RecyclerView.Adapter has methods like notifyItemInserted(int position) or notifyItemRemoved(int position) to notify that specific the item is added or removed and, the animation when item is add or remove is already handle when you called those method.
Moreover, right now it is very easy for RecyclerView to mimic the ViewPager behavior by using SnapHelper. There is PagerSnapHelper, and the behavior of ViewPager can be obtained with just a few lines of code. You can contact me if you want the code.
There is no comparison between this two. basically in ViewPager you can scroll only one item at time (either left or right), and in RecyclerView you can scroll to any index. it all depends on your requirements how you want to use it. you need to develop fragments for ViewPages, one for each page. as in RecyclerView you will have a item which will be used by adapter. both of them are easy to implement. there are numerous examples on both of them, you can have a look and get started.

Android Swipe Dismiss multiple items for RecyclerView

I will need to create cards layout mimicking cards found in Google Now. To do so, I've used a RecyclerView and each row as both the header and item. Pretty skeptical with this approach however.
The problem I'm facing is to mimic the swiping behaviour. Swiping at the header will also move the entire card (header + items) together.
To do so, I managed to edit the SwipeDismissRecyclerViewTouchListener and the adapter to remove the affected items. But after that, the visual would get clunky whereby remaining items would have random empty spaces in between or height that does not match.
How and what is the correct way to approach this? Should I instead use another way to populate the cards?

Categories

Resources