I\'m implementing drag\'n\'drop for views. When drag is started, I set visibility of the view to INVISIBLE
, then, if the drag was interrupted - back to VI
The best way is :
view.post(new Runnable() {
public void run() {
view.setVisibility(View.VISIBLE);
}
});
if we use:
if (event.getAction() == DragEvent.ACTION_DRAG_ENDED) {
final View droppedView = (View) event.getLocalState();
droppedView.post(new Runnable(){
@Override
public void run() {
droppedView.setVisibility(View.VISIBLE);
}
});
}
you will still get force close Null.pointer. ...
Maybe this can help. here in the given link says: instead of DragEvent.ACTION_DRAG_ENDED
use DragEvent.ACTION_DROP
.
You can try this
if (event.getAction() == DragEvent.ACTION_DRAG_ENDED) {
final View droppedView = (View) event.getLocalState();
droppedView.post(new Runnable(){
@Override
public void run() {
droppedView.setVisibility(View.VISIBLE);
}
});
}
Looks like Android itself trying to access View state at the same time as you end dragging.
EDIT
More precise explanation. By setting setVisibility()
, you're including or excluding View
from Android internal collection of views, that should respond to drag events. This collection is used during dispatch of drag events, and therefore by trying to setVisibility
(in other words, trying to modify listeners of drag events) you're causing ConcurrentModificationException