mrKlar / PagedDragDropGrid

An Android ViewGroup that implements a paged grid with drag'n'drop moveable items
406 stars 185 forks source link

How to Catch Drop Event? #17

Closed musaulker closed 11 years ago

musaulker commented 11 years ago

How do I catch the drop event?

lkorth commented 11 years ago

If you take a look at DragDropGrid at line 200, this is where the touch up and reordering is handled if something was dragged.

musaulker commented 11 years ago

I modified ExamplePagedDragDropGridAdapter and added a method; isOrdered(), to check the list is ordered or not, for a special purpose.

public boolean isOrdered(){
    List<Item> items = pages.get(0).getItems();
    Long previousIndex = items.get(0).getId();
    for (int i = 1; i < items.size(); i++) {
        Long currentIndex = items.get(i).getId();
        if(currentIndex > previousIndex){
            previousIndex = currentIndex;
            continue;
        }
        else{
            return false;
        }
    }
    return true;
}

I need to catch somehow the drop event so later I can check if the list is ordered or not.

So from my Activity how can I catch the drop event? (Without modifying core source codes for DragDropGrid class)

lkorth commented 11 years ago

Any time there is a drop that causes a reorder, swapItems() will be called.

musaulker commented 11 years ago

I understood. But what about a listener? Are there any listener exists on DragDropGrid or adapter or items that I can listen it to catch drop events to call my method in adapter?

Thanks

On Fri, Apr 5, 2013 at 5:36 PM, Luke Korth notifications@github.com wrote:

Any time there is a drop that causes a reorder, swapItems()https://github.com/mrKlar/PagedDragDropGrid/blob/master/example/src/ca/laplanete/mobile/example/ExamplePagedDragDropGridAdapter.java#L209will be called.

— Reply to this email directly or view it on GitHubhttps://github.com/mrKlar/PagedDragDropGrid/issues/17#issuecomment-15959144 .

M.Musa Ülker

lkorth commented 11 years ago

I don't believe so

musaulker commented 11 years ago

Then, whats your advice?

On Fri, Apr 5, 2013 at 6:05 PM, Luke Korth notifications@github.com wrote:

I don't believe so

— Reply to this email directly or view it on GitHubhttps://github.com/mrKlar/PagedDragDropGrid/issues/17#issuecomment-15960891 .

M.Musa Ülker

lkorth commented 11 years ago

Use swapItems() or modify DragDropGrid

mrKlar commented 11 years ago

You could create your own listener and use it in the adapter when swapItems is called.