[mono-android] change to a Java cast after 4.2.2

John Murray john at murray.gb.com
Thu Jun 14 11:46:49 UTC 2012


The item are slightly more complex - its a three line per item listbox
The adapter is set thus 
garally2.SetAdapter(ad1, new
EventHandler<DialogClickEventArgs>(garlistclick));

yes I did previously have 4.0.x


I am not clear what you mean by 'what is the run time type of 'sender' ? it
is spec'd as an object then cast to android .dialog thus

   public void garlistclick(object sender, DialogClickEventArgs ee)
         {
            AlertDialog send = (AlertDialog)sender;
            JavaList selitem3 =
(JavaList)send.ListView.GetItemAtPosition(ee.Which);

So instead of SetAdapter I should use SetITems ? Is that it or am I being
too simplistic?
If I did 
            builder.SetItems (ad1, (o, e) => {garlistclick();});

would that be the right format to specify the adapter list?


Tx so far
J


-----Original Message-----ly have 4.0.x


From: Jonathan Pryor [mailto:jonp at xamarin.com] 
Sent: 13 June 2012 19:48
To: john at murray.gb.com; Discussions related to Mono for Android
Subject: Re: [mono-android] change to a Java cast after 4.2.2

On Jun 13, 2012, at 11:00 AM, John Murray wrote:
> Since installing 4.2.2 I now get an unhandled exc on this code

What is the runtime type of your `sender` parameter?

What release were you using prior to 4.2.2? If you were on 4.0.x previously,
you're probably hitting:

	
http://docs.xamarin.com/android/Releases/Mono_For_Android_4/Mono_for_Android
_4.2#Breaking_Changes

	The various FooEventArgs.V properties have been removed, and their
value is now the sender parameter of the EventHandler delegate.

> Which I've probably been lucky to get away with before... trouble is I
don't know what to do next to solve it Its a dialog click method

What code are you using garlistclick() with? For example, if I do:

	var builder = new Android.App.AlertDialog.Builder (this);
	builder.SetItems (new[]{"one", "two", "three"}, (o, e) => {
		Console.WriteLine ("Handler invoked! sender.GetType()={0}",
o.GetType ().FullName);
	});
	builder.Create ().Show ();

`o.GetType()` is Android.App.AlertDialog. Presumably you're not using
AlertDialog.Builder.SetItems(); what are you using?

Thanks,
 - Jon




More information about the Monodroid mailing list