mail-archives/monodroid/2011-December/007711.html

136 строки
3.9 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE> [mono-android] How to use OnProgressChanged in m4a?
</TITLE>
<LINK REL="Index" HREF="index.html" >
<LINK REL="made" HREF="mailto:monodroid%40lists.ximian.com?Subject=%5Bmono-android%5D%20How%20to%20use%20OnProgressChanged%20in%20m4a%3F&In-Reply-To=1323453123349-5062534.post%40n5.nabble.com">
<META NAME="robots" CONTENT="index,nofollow">
<META http-equiv="Content-Type" content="text/html; charset=us-ascii">
<LINK REL="Previous" HREF="007709.html">
<LINK REL="Next" HREF="007714.html">
</HEAD>
<BODY BGCOLOR="#ffffff">
<H1>[mono-android] How to use OnProgressChanged in m4a?</H1>
<B>Jonathan Pryor</B>
<A HREF="mailto:monodroid%40lists.ximian.com?Subject=%5Bmono-android%5D%20How%20to%20use%20OnProgressChanged%20in%20m4a%3F&In-Reply-To=1323453123349-5062534.post%40n5.nabble.com"
TITLE="[mono-android] How to use OnProgressChanged in m4a?">jonp at xamarin.com
</A><BR>
<I>Fri Dec 9 14:23:43 EST 2011</I>
<P><UL>
<LI>Previous message: <A HREF="007709.html">[mono-android] How to use OnProgressChanged in m4a?
</A></li>
<LI>Next message: <A HREF="007714.html">[mono-android] How to use OnProgressChanged in m4a?
</A></li>
<LI> <B>Messages sorted by:</B>
<a href="date.html#7711">[ date ]</a>
<a href="thread.html#7711">[ thread ]</a>
<a href="subject.html#7711">[ subject ]</a>
<a href="author.html#7711">[ author ]</a>
</LI>
</UL>
<HR>
<!--beginarticle-->
<PRE>On Dec 9, 2011, at 12:52 PM, Hernani Delindro wrote:
&gt;<i> Hello, I'm still new to Mono for Android, and C# in general, but I would like
</I>&gt;<i> some help on how to &quot;translate&quot; the following code to m4a, because I'm
</I>&gt;<i> having trouble understanding with how listeners and callbacks are
</I>&gt;<i> implemented in m4a.
</I>&gt;<i>
</I>&gt;<i> webview.SetWebChromeClient(new WebChromeClient() {
</I>&gt;<i> public void OnProgressChanged(WebView view, int progress)
</I>&gt;<i> {
</I>&gt;<i> activity.SetTitle(&quot;Loading...&quot;);
</I>&gt;<i> activity.SetProgress(progress * 100);
</I>&gt;<i>
</I>&gt;<i> if(progress == 100)
</I>&gt;<i> activity.SetTitle(Resource.String.app_name);
</I>&gt;<i> }
</I>&gt;<i> });
</I>
That is an anonymous inner class, which C# doesn't support. Instead, you need to turn it into a &quot;normal&quot; class (either at top-level or a nested type, doesn't really matter):
class WebChromeClientDelegator : WebChromeClient {
public Action&lt;WebView, int&gt; ProgressChanged;
public override void OnProgressChanged (WebView view, int newProgress)
{
if (ProgressChanged != null)
ProgressChanged (view, newProgress);
}
}
// ...
webview.SetWebChromeClient (new WebChromeClientDelegator () {
ProgressChanged = (view, progress) =&gt; {
activity.SetTitle (&quot;Loading...&quot;);
activity.SetProgress (progress * 100);
if (progress == 100)
activity.SetTitle (Resource.String.app_name);
},
});
- Jon
</PRE>
<!--endarticle-->
<HR>
<P><UL>
<!--threads-->
<LI>Previous message: <A HREF="007709.html">[mono-android] How to use OnProgressChanged in m4a?
</A></li>
<LI>Next message: <A HREF="007714.html">[mono-android] How to use OnProgressChanged in m4a?
</A></li>
<LI> <B>Messages sorted by:</B>
<a href="date.html#7711">[ date ]</a>
<a href="thread.html#7711">[ thread ]</a>
<a href="subject.html#7711">[ subject ]</a>
<a href="author.html#7711">[ author ]</a>
</LI>
</UL>
<hr>
<a href="http://lists.ximian.com/mailman/listinfo/monodroid">More information about the Monodroid
mailing list</a><br>
</body></html>