Note that there are some explanatory texts on larger screens.

plurals
  1. POmissing ImageView sources the first time i Drag and Drop in my GridView
    text
    copied!<p>I made a drag and drop GridView. Everything works perfectly except for the first drag and drop. I cant find the reason why it only happends the first time.</p> <p>The first time i drag a item over the other items in the gridview, the imageview sources of the items are lost. When i drop it the sources will be fixed.. After that every thing will work just normal. Any idea how i can fix this or the cause of the strange behavior. Every help is welcome.</p> <p>here is my touchListener wich will handle the drag and drop:</p> <pre><code>mGridView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { GridView parent = (GridView) v; int x = (int) event.getX(); int y = (int) event.getY(); int position = parent.pointToPosition(x, y); if (position &gt; AdapterView.INVALID_POSITION) { int count = parent.getChildCount(); for (int i = 0; i &lt; count; i++) { View curr = parent.getChildAt(i); curr.setOnDragListener(new View.OnDragListener() { @Override public boolean onDrag(View v, DragEvent event) { boolean result = true; int action = event.getAction(); switch (action) { case DragEvent.ACTION_DRAG_STARTED: break; case DragEvent.ACTION_DRAG_LOCATION: break; case DragEvent.ACTION_DRAG_ENTERED: setBlueFilterOnImageView((ImageView) v, getActivity()); break; case DragEvent.ACTION_DRAG_EXITED: clearColorFilterOnImageView((ImageView) v); break; case DragEvent.ACTION_DROP: if (event.getLocalState() == v) { result = false; } else { View droped = (View) event.getLocalState(); View target = v; app.myProfile().removeProfilePhotoAtIndex(((DragGridItemHolder) droped.getTag()).position); app.myProfile().insertProfilePhoto(((DragGridItemHolder) droped.getTag()).id, ((DragGridItemHolder) target.getTag()).position); mAdapter.notifyDataSetChanged(); } break; case DragEvent.ACTION_DRAG_ENDED: clearColorFilterOnImageView((ImageView) v); break; default: result = false; break; } return result; } }); } int relativePosition = position - parent.getFirstVisiblePosition(); View target = (View) parent.getChildAt(relativePosition); DragGridItemHolder holder = (DragGridItemHolder) target.getTag(); String text = holder.id; ClipData data = ClipData.newPlainText("DragData", text); target.startDrag(data, new View.DragShadowBuilder(target), target, 0); } } return false; } }); </code></pre> <p><strong>EDIT</strong></p> <pre><code>public static void setBlueFilterOnImageView(ImageView imageView, Context context){ PorterDuffColorFilter blueFilter = new PorterDuffColorFilter( context.getResources().getColor(R.color.grid_state_focused), PorterDuff.Mode.SRC_ATOP); imageView.setColorFilter(blueFilter); imageView.setBackgroundColor(context.getResources().getColor( R.color.grid_state_pressed)); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload