What is the proper way to imitate base class for Mortar views

77 Views Asked by At

Mortar views inherit from different layouts (LinearLayout, RelativeLayout, etc).

I want to have some basic functionality that will be shared across all views.

The problem is that I cannot use inheritance since views inherited from different layouts.

How you usually solve this problem?

1

There are 1 best solutions below

0
On

I have a special class derived from FrameLayout which acts as proxy to view inflation. It has custom attributes: layoutResId, layoutPhoneResId, layoutTabletResId, layoutEmptyResId, layoutLoadingResId. These are references to other resources (which can be any layout). After inflation of LayoutDirector (in onFinishInflate()), these layout views are inflated and added as children to this view. This approach allows to inflate different views for tablet and phone (by special condition), custom empty and loading views. And this allows shared functionality across all views too.