I've tried my best to update the dnd sample to c# from
http://developer.android.com/guide/topics/ui/drag-drop.html. I've got an
imageview that I am using. The problem is that nothing in myDragListener seems
to fire. I think the problem is when I instantiate the class, I am handing in
the incorrect handle. Any suggestions on getting this to work? The second
problem is that the example lists a .SetColorFilter method on a view doesn't
seem to be there. Is there another method I can use? Any thoughts/ideas are
appreciated.
Wally
// Sets the drag event listener for the View
iv.SetOnDragListener(mDragListen);....................................................
protected class myDragEventListener : View.IOnDragListener
{
Context _c;
public myDragEventListener(Context c)
{
_c = c;
}
// This is the method that the system calls when it dispatches a
drag event to the
// listener.
public bool OnDrag(View v, DragEvent e)
{
// Defines a variable to store the action type for the incoming
event
var action = e.Action;
// Handles each of the expected events
switch (action)
{
case Android.Views.DragAction.Started:
// Determines if this View can accept the dragged data
if
(e.ClipDescription.HasMimeType(ClipDescription.MimetypeTextPlain))
{
// As an example of what your application might do,
// applies a blue color tint to the View to
indicate that it can accept
// data.
v.SetBackgroundColor(Android.Graphics.Color.Blue);
//v.SetColorFilter(Android.Graphics.Color.Blue);
// Invalidate the view to force a redraw in the new
tint
v.Invalidate();
// returns true to indicate that the View can
accept the dragged data.
return (true);
}
else
{
// Returns false. During the current drag and drop
operation, this View will
// not receive events again until ACTION_DRAG_ENDED
is sent.
return (false);
}
case Android.Views.DragAction.Entered:
// Applies a green tint to the View. Return true; the
return value is ignored.
v.SetBackgroundColor(Android.Graphics.Color.Green);
//v.setColorFilter(Color.GREEN);
// Invalidate the view to force a redraw in the new tint
v.Invalidate();
return (true);
case Android.Views.DragAction.Location:
// Ignore the event
return (true);
case Android.Views.DragAction.Exited:
// Re-sets the color tint to blue. Returns true; the
return value is ignored.
//v.setColorFilter(Color.BLUE);
v.SetBackgroundColor(Android.Graphics.Color.Blue);
// Invalidate the view to force a redraw in the new tint
v.Invalidate();
return (true);
case Android.Views.DragAction.Drop:
// Gets the item containing the dragged data
ClipData.Item item = e.ClipData.GetItemAt(0);
// Gets the text data from the item.
var dragData = item.Text;
// Displays a message containing the dragged data.
Toast.MakeText(v.Context, "Dragged data is " +
dragData, ToastLength.Long).Show();
// Turns off any color tints
//v.clearColorFilter();
// Invalidates the view to force a redraw
v.Invalidate();
// Returns true. DragEvent.getResult() will return true.
return (true);
case Android.Views.DragAction.Ended:
// Turns off any color tinting
//v.clearColorFilter();
// Invalidates the view to force a redraw
v.Invalidate();
// Does a getResult(), and displays what happened.
if (e.Result)
{
Toast.MakeText(v.Context, "The drop was handled.",
ToastLength.Long).Show();
}
else
{
Toast.MakeText(v.Context, "The drop didn't work.",
ToastLength.Long).Show();
};
// returns true; the value is ignored.
return (true);
// An unknown action type was received.
default:
Android.Util.Log.Error("DragDrop Example", "Unknown
action type received by OnDragListener.");
return (true);
};
}
IntPtr IJavaObject.Handle
{
get { return _c.Handle; }
}
}
_______________________________________________
Monodroid mailing list
[email protected]
UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid