Greg Shackles and Johnathan Pryor have an article on the subject;

http://mono-for-android.1047100.n5.nabble.com/another-Java-versus-C-how-to-td4332736.html
"C# doesn't allow anonymous implementations like Java (ie: the listener
interfaces) so those get replaced by events/delegates in C#. If you wanted
you could still use the interface since SetItems has a bunch of overloads
[0] but you'd have to define a real class that implements it separately to
use it here. Here's an example of using a lambda to do it:"

var stuff = new string[] { "foo", "bar" };

new AlertDialog.Builder(this)
  .SetTitle("Pick something")
  .SetItems(stuff, (sender, args) =>
  {
    Toast
      .MakeText(this, stuff[(int)args.Which], ToastLength.Short)
      .Show();
  })
  .Show();

Since you mentioned wanting to avoid the lambda style of nesting the
method, you could define a separate callback method like this:

new AlertDialog.Builder(this)
  .SetTitle("Pick something")
  .SetItems(stuff, listItemClicked)
  .Show();

private void listItemClicked(object sender,
Android.Content.DialogClickEventArgs args)
{
  Toast
    .MakeText(this, stuff[(int)args.Which], ToastLength.Short)
    .Show();
}

On Wed, Nov 23, 2011 at 11:32 PM, Oscar R Lopez <ironart...@hotmail.com>wrote:

> Hi,
>
> I´ve just ported QuickActions from Java to C#
>
> http://www.xoriant.com/blog/mobile-application-development/android-ui-design-pattern-%E2%80%93-quick-action-bar.html
>
> http://www.xoriant.com/blog/mobile-application-development/android-ui-design-pattern-%E2%80%93-quick-action-bar.html
>
> At one point i need to set the ClickListener for the item of the
> quickactionbar
>
>
> Is there any way of doing this with lambdas or delegate?
>
> At this point, i need to make a class that implements IOnClickListener with
> OnClick method overrided. It´s ugly.
>
> Bye
>
> --
> View this message in context:
> http://mono-for-android.1047100.n5.nabble.com/IOnClickListener-with-lambda-tp5016496p5016496.html
> Sent from the Mono for Android mailing list archive at Nabble.com.
> _______________________________________________
> Monodroid mailing list
> Monodroid@lists.ximian.com
>
> UNSUBSCRIBE INFORMATION:
> http://lists.ximian.com/mailman/listinfo/monodroid
>



-- 
Glen Hassell
Inner Technique
http://innertech.com.au/
Office: 03 9687 0006
Mobile: +61 (0) 438 340 385
_______________________________________________
Monodroid mailing list
Monodroid@lists.ximian.com

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

Reply via email to