[mono-android] Passing callback functions from Javascript to Mono
Terry151151
Terry at Terry-Watts.com
Mon Jun 11 13:36:51 UTC 2012
I have a JQuery script that calls a Javascript interface and I would like to
pass two callback functions to Mono. When the C# function get called from
the WebView the two functions are null. Any idea how to pass the callback
functions?
Simplified Code:
JQuery:
$(document).ready( function()
{
var OkBtn = $( '#OkBtn' );
var DisableOk = function()
{
OkBtn.attr( 'disabled', true );
};
var EnableOk = function()
{
OkBtn.attr( 'disabled', false );
};
var HttpAddress = $( '#HttpAddress' );
HttpAddress.click(function (e)
{
window.Device.HttpCheck( HttpAddress.val(), EnableOk, DisableOk );
});
-------------------------------------------------------------------------------------------
C#
public class JavaScriptInterface : Java.Lang.Object
{
[Export]
public Java.Lang.Boolean HttpCheck( Java.Lang.String _url,
Java.Lang.Runnable OnSuccess, Java.Lang.Runnable OnFail )
{
bool Result = false;
Java.Lang.Boolean Retval;
try
{
string url = _url.ToString();
if( Url.IsValidUrl( url ) )
{
OnSuccess.Run(); // OnSuccess is null
Result = true;
}
else
{
OnFail.Run(); // OnFail is null
Result = false;
}
}
finally
{
Retval = new Java.Lang.Boolean( Result );
}
return Retval;
}
}
Thanks in advance
Terry
--
View this message in context: http://mono-for-android.1047100.n5.nabble.com/Passing-callback-functions-from-Javascript-to-Mono-tp5710278.html
Sent from the Mono for Android mailing list archive at Nabble.com.
More information about the Monodroid
mailing list