Type cast from Java.Lang.Object to native CLR type in MonoDroid

Viewed 13426

How to cast Java.Lang.Object to some native type?

Example:

ListView adapter contains instances of native type Message. When i am trying to get SelectedItem from ListView it returns instance of Message type casted to Java.Lang.Object, but I can't find solution to cast Java.Lang.Object back to Message.

var message = (Message)list.SelectedItem;
// throws  Error    5   Cannot convert type 'Java.Lang.Object' to 'Message'

Please Help.

8 Answers

If for some reason GetChildAtPosition is not possible, serialise the object to json string and then deserialise the string back to native class.

Related