rainer
rainer

Reputation: 3411

Codename One dragged-over container quickly dissappears

I have an Android application that uses drag and drop operations. I haven't used drag and drop often, so I am just starting to learn how they work and what the implications might be.

In my app, whenever I drop the component over the target, the target sort of "flashes", meaning it disappears for a brief moment and than reappears again.

Here a link to the video with the app in its current stage.

I suppose this is due to the animation of the form. If so, how can I disable it, or stop the target from flashing?

Below is my code. It is still rudimentary, since I just started to work on the project.

public void testDrag () {

    Container containerDropTarget = new Container();
    Container container = new Container(new GridLayout(5,1));
    Label label = new Label("test test test test test test");
    Button buttonTwo = new Button("Test");
    
    buttonTwo.addDragOverListener(l-> {
        containerDropTarget.setUIID("DialogTest");
    });
    
    containerDropTarget.setUIID("LetterHolder");
    
    buttonTwo.setDraggable(true);
    containerDropTarget.setDropTarget(true);
    
    container.add(label).add(containerDropTarget);
    
    form.add(container).add(buttonTwo);
    form.show();
}

Upvotes: 2

Views: 66

Answers (1)

Shai Almog
Shai Almog

Reputation: 52760

I don't have the UIIDs defined so I used this code based on your test case and it worked correctly. I also added a label to the drop container so it could be found:

Container containerDropTarget = new Container() {
    @Override
    public void drop(Component dragged, int x, int y) {
        super.drop(dragged, x, y); 
        setUIID("Container");
    }
};
containerDropTarget.add(new Label("Drop Target"));
Form form = new Form("Test Drag", BoxLayout.y());
Container container = new Container(new GridLayout(5,1));
Label label = new Label("test test test test test test");
Button buttonTwo = new Button("Test");

buttonTwo.addDragOverListener(l-> {
    //containerDropTarget.setUIID("DialogTest");
    containerDropTarget.getAllStyles().setBgColor(0xff0000);
    containerDropTarget.getAllStyles().setBgTransparency(0xff);
    containerDropTarget.repaint();
});

containerDropTarget.setUIID("LetterHolder");

buttonTwo.setDraggable(true);
containerDropTarget.setDropTarget(true);

container.add(label).add(containerDropTarget);

form.add(container).add(buttonTwo);
form.show();

Upvotes: 1

Related Questions