Giter Club home page Giter Club logo

Comments (5)

iPaulPro avatar iPaulPro commented on August 21, 2024

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.

scriptacus avatar scriptacus commented on August 21, 2024

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.

SUPERCILEX avatar SUPERCILEX commented on August 21, 2024

@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.

kokilaw avatar kokilaw commented on August 21, 2024

@SUPERCILEX did you find a way to do drag and drop across multiple view types?

from android-itemtouchhelper-demo.

SUPERCILEX avatar SUPERCILEX commented on August 21, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.