*EDIT: To answer my own question, I had to add EditorViewModel as an import to the parent abstract class in the outer layout, and cast the viewModel to the parent class using app:viewModel="@{((EditorViewModel)viewModel)}", that was it! I swear I don't recall doing this cast before though...*
My problem results because the included layout is defining a type which is the parent abstract class, and NOT the child concrete class, of the viewModel the outer layout is trying to share with the included layout.
I've confirmed that changing the included layout's type to the child concrete class' type fixes the issue, however, it should work with the abstract class type...
Here is how I define my viewModel variable, this is the concrete class in the type below:
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:bind="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="viewModel"
type="com.ootpapps.gpeofflinedatacollection.viewmodels.EquipmentEditorViewModel" />
</data>
...
A few statements later I include the layout, attempting to share the viewModel from above:
<include
layout="@layout/layout_spinner_location"
app:viewModel="@{viewModel}" />
Within the included layout the variable viewModel is defined as follows:
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bind="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="viewModel"
type="com.ootpapps.gpeofflinedatacollection.viewmodels.EditorViewModel" />
</data>
And of course here's the EquipmentEditorViewModel showing it extends the abstract parent class EditorViewModel (defined as the parent class type above in the included layout):
public class EquipmentEditorViewModel extends EditorViewModel<Equipment> {
The error I receive is:
****/ data binding error ****msg:Cannot find the setter for attribute 'app:viewModel' with parameter type com.ootpapps.gpeofflinedatacollection.viewmodels.EquipmentEditorViewModel on com.ootpapps.gpeofflinedatacollection.databinding.LayoutSpinnerLocationBinding. file:C:\Users\Ryan\AndroidstudioProjects\GPEOfflineDataCollection\app\src\main\res\layout\content_equipment_editor.xml loc:31:33 - 31:41 ****\ data binding error ****
As I mentioned above, changing the type in layout_spinner_location to "EquipmentEditorViewModel" fixes the error, HOWEVER, I need to use the abstract type in order to re-use this view as it doesn't always use an EquipmentEditorViewModel, sometimes it needs a "ToolEditorViewModel" or a "MeasurmentEditorViewModel" all of which extend EditorViewModel.
Thank you very much for your help. Maybe I will get lucky and George Mount will stop by.