Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to do drag and drop with different view types? #54

Open
kokilaw opened this issue Dec 5, 2017 · 3 comments
Open

How to do drag and drop with different view types? #54

kokilaw opened this issue Dec 5, 2017 · 3 comments

Comments

@kokilaw
Copy link

kokilaw commented Dec 5, 2017

I need to implement the drag and drop for items with different view types. I tried with following code

override fun onMove(recyclerView: RecyclerView, source: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder): Boolean {
        // Notify the adapter of the move
        mAdapter.onItemMove(source.adapterPosition, target.adapterPosition)
        return true
}

without

if (source.itemViewType != target.itemViewType) {
            return false
}

but it doesn't work as I expected. I'm using a grid layout by the way.

@safakesberk
Copy link

safakesberk commented Jan 16, 2018

Did you change getItemViewType, onCreateViewHolder and onBindViewHolder methods in your adapter class?

@kokilaw
Copy link
Author

kokilaw commented Jan 20, 2018

Yes. RecylerView is working fine with different view types. Drag and drop between different view types is the place that that I'm stuck at.

@AndroidDeveloperLB
Copy link

AndroidDeveloperLB commented Jul 28, 2019

To decide if a viewHolder should be drag-able and/or swipe-able, I think you need to do it in the getMovementFlags function. There you have a change to decide if you want to allow drag and/or swipe for the given ViewHolder.

To decide if a viewHolder can be switched with another one, you have onMove .
Here, made a sample for this :
https://github.com/AndroidDeveloperLB/RecyclerViewDragAndDropTest

Weird thing is that the animation might be weird in some cases. Reported it here:
https://issuetracker.google.com/issues/138465468

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants