Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drag and drop Android Gallery images

I am working on an application which allows users to order items from a Gallery widget. The user must have the capability to select an order from the Gallery widget. Orders should display as images on the Gallery and the user must have the capability to drag an image and place it onto order button.

I am stuck with the drag and drop part. How do I drag and drop images using the Gallery widget in Android?

like image 562
user1006673 Avatar asked Oct 21 '11 08:10

user1006673


2 Answers

never did this so I can't say for sure but here is how I would approach the problem:

I would extend the existing gallery. Then Override the onDown Method or something similar to be able to detect which image is touched.

Then I would display a new image view with the image where the finger is, that listens to the touched moved event.

then on touch released, you can check where the component dropped.

-

It could also be an idea to write your own quick gallery in a scroll panel, this way you have much mor control over the events ;)

Cheers

Jason

like image 59
Jason Rogers Avatar answered Oct 13 '22 01:10

Jason Rogers


One approach is to extend Gallery and implement AdapterView.OnItemClickListener.

Your drag action could be implemented as:

@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position,
        long id) {
    if (!view.isTouched()) {
        return false;
    }
    customDragController.startDrag(view, this, view, CustomDragController.MOVE);
    return true;
}

For an more complete example of how this can be implemented including a customDragController please have a look at this github project.

like image 26
onosendai Avatar answered Oct 13 '22 03:10

onosendai