Search code examples
androidandroid-viewviewgroup

ViewGroup_instance.addView(View_instance), how a subclass can accept a super class instance?


What I think about this method:

ViewGroup, which is subclass of View, can not accept View_instance because of the inheritance hierarchy, so ViewGroup_instance is working as container for View_instance.

It is correct?


Solution

  • The ViewGroup.addView() methods have nothing to do at all with inheritance, those methods are just part of the ViewGroup implementation(besides the inherited behavior from View) to allow the adding of child views. The addView() methods use the View super class to allow the addition of any View(simple view or layout grouping views).