2

Consider the documentationfor the OnTouchListener which is clear:

Called when a touch event is dispatched to a view.

Perfect! I get it. I'm looking for this kind of description about interface methods which can be overloaded to create things like custom Animations, Rows, Adapters/whatever.

Take this documentation for the getView() method of the Adapter Interface as an example of my confusion. Its my understanding that getView() gets called by android anytime a new view is required by the adapter, like when you scroll through a list view and a new cell gets added. But I don't see how I could come to that conclusion from the documentation.

For getView() it seems intuitive. But other interfaces like SectionIndexor I don't think are. I frequently struggle overloading interface methods because I can't figure out how they interact at runtime. Is this documented?

FakeSaint
  • 492
  • 5
  • 8
  • Well GetView is called when your ListView is trying to set a Template View to its ListItems, So basically anything related to cell creation is added to this – FreakyAli Aug 29 '18 at 05:52
  • Thanks, how is it you learned this? Maybe my question is too general, but I want to know how I can determine how interface or base class methods interact. As a more recent example, I was trying to create an index for a list view. The docs show what the interface methods do, but it takes me finding examples online to discover how they actually interact. (I'm not looking for clarification about ISectionIndex, rather I'm lost how it is people figure these things out from the docs) – FakeSaint Aug 30 '18 at 22:31
  • Well that is simple you need to understand c# as well as a little background to native android first to know what needs to be done for example there is a touch listener, Now since its a listener then you should know that its an interface, that's android, Now Anonymous classes cannot be used in xamarin android its C# – FreakyAli Aug 31 '18 at 05:58
  • You can also check the c# object browser to understand what a particular properties return type is and then use that for the same to understand what you need to do. – FreakyAli Aug 31 '18 at 06:06
  • Thanks you've been very helpful. Apologies I don't think I did my question justice, I've edited my original post. I'm looking for descriptions of how interface methods interact and how they relate to each other at runtime... or just a way I could figure this information out for myself – FakeSaint Aug 31 '18 at 19:35
  • Wait i will put an answer – FreakyAli Sep 04 '18 at 06:09

1 Answers1

1

The Microsoft documents define an interface as follows:

An interface contains definitions for a group of related functionalities that a class or a struct can implement.

There are minor differences in Java and C# interfaces which can be found here. (Assuming you to be from a Java background)

Now you have a confusion in between abstract class's overridden method and an interface method. Check the difference here

The GetView method is a method of the Android abstract class called BaseAdapter. Base Adapter abstract class and hence to get info on that first you need to look into BaseAdapter then find GetView method in it. And there you can get the exact description of the method and what it does. Note: that Xamarin.Android works exactly the same as native Android so you could use the same documentation for an understanding of the methods.

Note: Implementation differs from C# to Java.

Now an eg for an interface would be the IOnMapReadyCallback which is used as a callback by Xamarin.Android to check if the map is ready to be used.

Now interfaces in C# as per their naming convention begin with an I. eg: the Android java OnTouchListener interface becomes the IOnTouchListener in Xamarin Android and so on and so forth.

Now if you use an interface method this method is just defined and it is mandatory that you use that method in your class which you are inheriting it to, so this method will be added to that class and will not act as an overridden method like it does in case of abstract class.

Now in case, you want to understand when an interface method is invoked you need to check the Android documentation for that interface eg the OnMapReadyCallback then find the method you need to understand i.e. onMapReady

In case you don't understand anything revert.

Goodluck!

Happy coding.

FreakyAli
  • 13,349
  • 3
  • 23
  • 63
  • Wow thanks for sticking with me! So in the example of the GetView Method, to trace it through the docs: The abstract class BaseAdapter implements the ListAdapter interface, which implements the Adapter Interface which requires the GetView() method... But in the docs I don't see any specification about when that method will be called at Runtime: https://developer.android.com/reference/android/widget/Adapter.html#getView(int,%20android.view.View,%20android.view.ViewGroup) – FakeSaint Sep 04 '18 at 19:59
  • So like in the example you posted, I can see in the documentation that the method onMapReady() gets called when a map is ready to be used. I can't find a simmilar description of the getView() method. Maybe its just I find the documentation too vague, but If thats all there is then I guess thats how it goes! – FakeSaint Sep 04 '18 at 20:02
  • Well for me the description that it does have seems to be more than enough to understand what it does and probably it differs from person to person just my perspective anyway in case you don't understand anything you can always ask here, Also getview has no mention of the same for an obvious reason as everyone knows arrayadapter getview is called to get the template of current view – FreakyAli Sep 05 '18 at 07:00