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

前端 未结 8 1140
花落未央
花落未央 2021-02-02 13:38

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

8条回答
  •  遥遥无期
    2021-02-02 13:49

    All of the above answers are correct but I found the simplest way for my case was to make the object a subclass of Java.Lang.Object.

    For example I'm writing a Android app in Monotouch, mimicking the concept of a UITableView in iOS using the ExpandableListAdapter, which requires the equivalent of UITableViewCells, so I subclassed cell objects from Java.Lang.Object allowing me to implement a subclass of ExpandableListAdapter such as

    public override Java.Lang.Object GetChild(int position, int childPosition)
    

    Etc.

提交回复
热议问题