How to limit Drag and Drop to certain views only?

Asked

Viewed 40 times

3

I wonder if I can control what goes into my layout (DROP) Because of the image view below I wish only "imgu" could enter my layout, the rest not:

findViewById(R.id.imga).setOnLongClickListener(new MyOnLongClickListener());
    findViewById(R.id.imge).setOnLongClickListener(new MyOnLongClickListener());
    findViewById(R.id.imgi).setOnLongClickListener(new MyOnLongClickListener());
    findViewById(R.id.imgo).setOnLongClickListener(new MyOnLongClickListener());
    findViewById(R.id.imgu).setOnLongClickListener(new MyOnLongClickListener());

    findViewById(R.id.layoutrecebe).setOnDragListener( new MyOnDragListener(1));

1 answer

2

In the method onDrag(), of your Ondraglistener implementation, check that the id of the received view is the one you want if it is not returned false:

@Override
public boolean onDrag(View v, DragEvent event) {

    if(v.getId() != R.id.imgu) return false;
    ...
    ...
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.