This is a migrated thread and some comments may be shown as answers.

How to use C# insted Java.Lang.Object

1 Answer 720 Views
ListView - Xamarin.Android
This is a migrated thread and some comments may be shown as answers.
Valerio
Top achievements
Rank 1
Valerio asked on 03 Jan 2017, 08:46 PM

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

1 Answer, 1 is accepted

Sort by
0
Accepted
Lance | Manager Technical Support
Telerik team
answered on 05 Jan 2017, 04:53 PM
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
Tags
ListView - Xamarin.Android
Asked by
Valerio
Top achievements
Rank 1
Answers by
Lance | Manager Technical Support
Telerik team
Share this question
or