Comments (5)
View type is available from the ViewHolder
, by using the helper methods in the LayoutManager
, or even RecyclerView
itself (findViewHolderForAdapterPosition
). You haven't actually explained what/where the specific issue you're having is, so it's difficult to advise. Are you testing this project at master
? Have you made any changes?
SimpleItemTouchHelperCallback
at master
is already checking for the view type, and preventing the drag over unlike types:
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder source, RecyclerView.ViewHolder target) {
if (source.getItemViewType() != target.getItemViewType()) {
return false;
}
// ...
}
Simply adding something like this to RecyclerListAdapter
works fine in my testing:
@Override
public int getItemViewType(int position) {
return position < 3 ? 0 : 1;
}
The next part of this article series will deal with view type more, but it should be working fine, already. I'll need specific information, and likely code snippets, to help you any further.
from android-itemtouchhelper-demo.
Sorry for the lack of information. If getItemViewType() returns two different types of items (A and B for example), then obviously onMove won't allow them to swap. So as a test I commented out the block of code that you pasted above. In the case of a view with 3 items (A, B, B), I can drag items UP without issue, (e.g. ending up with B, A, B by dragging one of the B items to the top of the list), but if I try to drag a non-matching item DOWN the item being dragged gets detached during onMove somewhere in the RecyclerView code, which cancels the drag operation.
That said, I found the issue. I had based my implementation on your inital commit (the one that matches the tutorial, but then updated it to match the latest version. During that process I missed the fact that onItemMove changed to using Collections.swap(). The previous method of swapping is what was causing the issue.
from android-itemtouchhelper-demo.
@iPaulPro @scriptacus is there a way to support dragging and dropping an item across multiple view types without the drag being cancelled?
from android-itemtouchhelper-demo.
@SUPERCILEX did you find a way to do drag and drop across multiple view types?
from android-itemtouchhelper-demo.
@kokilayaa I don't remember what fixed it for me, but just remember to return true in onMove
and notify the adapter of your move in that method.
from android-itemtouchhelper-demo.
Related Issues (20)
- Create lib and publish to Jcenter HOT 1
- Issue with getMoveThreshold() HOT 3
- ss
- Swipe to dismiss doesnt work on Grid layout manager?
- Change scrolling speed while drag-and-drop?
- How can we save the new list after drag? HOT 2
- swipe delete
- Single notification - onMove
- Click and drag images working together HOT 1
- How to resize the recyclerview layout with a header (grid)
- Position of item not getting changed when its moved
- XĂ m lol
- Cannot Update the position of the dragged file HOT 1
- How to do drag and drop with different view types? HOT 3
- Sorts are not equal
- disable swipe
- How to get below item at the time of dragging ? not UP or Down
- Able to drag (not drop) outside of Recyclerview or add DragShadow
- not working in navigation drawer HOT 1
- Drag & Drop works slowly
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
đ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. đđđ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google â¤ď¸ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from android-itemtouchhelper-demo.