Issue
After reading dozens of Q&A regarding the subject, I couldn't find an answer to this situation.
In my app, the user is dragging different icons from one table layout to another (the bottom table layout is sort of an "icon keyboard").
After dragging the icon into the upper table (it replaces the placeholder image there), the user should be able to keep on dragging it there to different locations.
Right now, the first part work great. I'm able to drag the icons from the "keyboard" into the upper table layout. but for some reason, when I try to drag it between the different locations inside this layout, the imageView that should change into the icon, stays with the same drawable (the placeholder).
public boolean onDrag(View v, DragEvent event) {
ImageView imageOnBoard = (ImageView) v;
switch (event.getAction()) {
case DragEvent.ACTION_DRAG_STARTED:
break;
case DragEvent.ACTION_DRAG_ENTERED:
imageOnBoard.setBackgroundColor(0xFF00FF00);
break;
case DragEvent.ACTION_DRAG_EXITED:
imageOnBoard.setBackgroundColor(color.transparent);
imageOnBoard.setOnTouchListener(null);
break;
case DragEvent.ACTION_DROP:
imageOnBoard.setBackgroundColor(color.transparent);
TableRow tr1 = (TableRow) imageOnBoard.getParent();
int r=tr1.indexOfChild(imageOnBoard);
TableLayout tl1 = (TableLayout) tr1.getParent();
int c=tl1.indexOfChild(tr1);
ImageView strategyIcon = (ImageView) (event.getLocalState());
TableLayout source = (TableLayout) strategyIcon.getParent().getParent();
if (source.equals((TableLayout) findViewById(R.id.tableLayout)))
{
Drawable draw = strategyIcon.getDrawable();
imageOnBoard.setImageDrawable(draw);
}
else
{
Drawable draw = strategyIcon.getDrawable();
imageOnBoard.setImageDrawable(draw);
}
imageOnBoard.setVisibility(View.VISIBLE);
imageOnBoard.setOnTouchListener(new MyTouchListener());
break;
case DragEvent.ACTION_DRAG_ENDED:
break;
default:
break;
}
return true;
}
as you can see, i devided the DRAG_DROP action into the two cases (dragging from the "keyboard" and dragging inside the upper layout. I tested it, and it does go into the different cases, but the drawable object seems to be "unupdated".
Please help!
I now understand that the problem is while extracting the Drawable (getDrawable) for the second time, from the upper layout, I don't receive the current drawable, but the original one. How can I handle this?
Solution
I met same problem, when I set Image to a ImageView using image1.setImageDrawable(add);
sometimes it doesn't work, later I used glide to set image:
e.g. Glide.with(Activity.this).load(R.drawable.add).into(image1);
then it works fine
Answered By - Michael
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.