How to use C# insted Java.Lang.Object

2 posts, 1 answers
  1. Valerio
    Valerio avatar
    1 posts
    Member since:
    Jan 2017

    Posted 03 Jan Link to this post

    In http://docs.telerik.com/devtools/android/controls/listview/listview-getting-started is defined the class City : Java.Lang.Object

    This class is used in CityDataSourceAdapter http://docs.telerik.com/devtools/android/controls/listview/listview-dataoperations

     

    How to use a class City in C# not a Java.Lang.Object?

     

    Thanks

  2. Answer
    Lance | Tech Support Engineer, Sr.
    Admin
    Lance | Tech Support Engineer, Sr. avatar
    462 posts

    Posted 05 Jan Link to this post

    Hi Valerio,

    I see that you've submitted a similar question in a different forum thread, I'll repeat my answer here so that the community can see it as well.

    You don't always have to inherit from Java.Lang.Object. For example, in our RadListView Getting Started Documentation, there's a City class.

    In that case, you can create and show a list of Cities without inheriting from Java Object:

    public class City
    {
            public string Name { getset; }
            public string Country { getset; }
     
            public City(string name, string country)
            {
                Name = name;
                Country = country;
            }
     
            public override string ToString()
            {
                return $"{Name} ({Country})";
            }
    }

    I've attached a small, runnable, demo that shows this in action.


    Interfaces

    That said, there are times that you will need use Java Object. In the case of the RadListView Grouping example, you have to use it because you're implementing an Interface, IFunction, in the CountryGroupDescriptor.

    To learn more about why this is the case, please read the Implementing Interfaces paragraph in the Android Callable Wrappers Xamarin documentation.

    To quote that documentation's opening summary:

    Every time Android code needs to execute a virtual or interface method which is overridden or implemented in managed code, Xamarin.Android needs to provide a Java proxy so that the method gets dispatched to the appropriate managed type. These Java proxy types are Java code which have the "same" base class and Java interface list as the managed type, implementing the same constructors and declaring any overridden base class and interface methods.

    I hope I was able to clear this up for you, thank you for choosing UI for Xamarin!

    Regards,
    Lance | Tech Support Engineer, Sr.
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top