This is certainly due to my limited grasp of scopes and stuff but of some
kind soul could just give me a few pointers I'd be off and running again -
as it is I'm in brick wall mode
I have an activity called back up
Just presents a few buttons for different actions
I wanted to integrate it into the rest of the app which has a left and right
swipe on it using a tabhost - as this is a separate activity called from a
button I am running into problems as to what's in scope or not
So a rough outline of the code is below - what I want is for the right to
left swipe to 'Finish()' the activity - the gesture listener is working nice
and is detecting a right to left swipe- it's just how do I get the action I
want properly referenced at this point
As you can see I have tried various ruses - the only one which works is
passing the context to the gesture detect then goin
Cntxt.Dispose() - this is horrid - screen goes blank for a second and
mercifully it return to the previous activity but it seems to me like
setting fire to the shop at the end of the working day rather than just
closing it and locking the door - I'm sure it offers memory leaks
There is a button on the main screen (not shown in code below) which calls
Finish() which exits gracefully but Finish() as a method is not in scope in
the gesture detector
How do I do this - seems I must pass a reference to the activity to the
gesturelistener but I cant figure how I do that - I guess its blindingly
obvious but I really am brain dead on this one - help please anyone
John M
[Activity(Label = "Backup")]
public class backup : Activity
{
public bool res;
public GestureDetector gestureScannerB;
public GestureListenerB gestureListenerB;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.backup);
/////////////// do stuff
}
public override bool OnTouchEvent(MotionEvent e)
{
return gestureScannerB.OnTouchEvent(e);
}
public class GestureListenerB : Java.Lang.Object,
GestureDetector.IOnGestureListener
{
private Context cntxt;
private static int SWIPE_MAX_OFF_PATH = 270;
private static int SWIPE_MIN_DISTANCE = 80;
private static int SWIPE_THRESHOLD_VELOCITY = 70;
public GestureListenerB(Context Cntxt)
{
this.cntxt = Cntxt;
}
public bool OnDown(MotionEvent e)
{
return true;
}
public bool OnFling(MotionEvent e1, MotionEvent e2, float
velocityX, float velocityY)
{
try
{
if (System.Math.Abs(e1.GetY() - e2.GetY()) >
SWIPE_MAX_OFF_PATH)
{ return false;}
// right to left swipe
if (e1.GetX() - e2.GetX() > SWIPE_MIN_DISTANCE &&
System.Math.Abs(velocityX) > SWIPE_THRESHOLD_VELOCITY)
{
// Toast.MakeText(cntxt, "no further pages",
ToastLength.Short).Show();
// backup.endthis(); //enthis not in scope
// endthis(backup); // created a method in backup
class which did Finish but cant pass 'backup'
cntxt.Dispose(); // this works but seems messy
}
else if (e2.GetX() - e1.GetX() > SWIPE_MIN_DISTANCE &&
System.Math.Abs(velocityX) > SWIPE_THRESHOLD_VELOCITY)
{
// swiperight = true;
}
}
catch (System.Exception e)
{
// nothing
}
return false;
}
public void OnLongPress(MotionEvent e)
{
}
public bool OnScroll(MotionEvent e1, MotionEvent e2, float
distanceX, float distanceY)
{
return true;
}
public void OnShowPress(MotionEvent e)
{
}
public bool OnSingleTapUp(MotionEvent e)
{
return true;
}
}
}
_______________________________________________
Monodroid mailing list
[email protected]
UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid