I had to do something similar, but the differences are just large enough that I thought I'd post a separate answer in case it's useful for anyone. I have a spinner, and based on the selection in that spinner a different "chunk" of UI is displayed. This leverages ViewStub's ability to automatically inflate the first time the Visibility is set to Visible.
Per the suggestion above, I made it an extension method:
public static void SetViewStubVisibilityAndInflate(this View view, MvxFragment fragment, ViewStates visibility)
{
if (view is ViewStub && visibility == ViewStates.Visible)
{
var stub = (ViewStub)view;
using (new MvxBindingContextStackRegistration<IMvxAndroidBindingContext>((IMvxAndroidBindingContext)fragment.BindingContext))
{
stub.LayoutInflater = fragment.Activity.LayoutInflater;
stub.Inflate();
}
}
view.Visibility = visibility;
}
And here's the code in my UI (which could be cleaner...):
private void SetCurveInputsVisibility(View view)
{
var std = view.FindViewById(Resource.Id.CurveTypeStandard);
var stdVis = (ViewModel.Values.CurveType == ServoCurveType.Standard ? ViewStates.Visible : ViewStates.Gone);
std.SetViewStubVisibilityAndInflate(this, stdVis);
var expo = view.FindViewById(Resource.Id.CurveTypeExpo);
var expoVis = (ViewModel.Values.CurveType == ServoCurveType.Exponential ? ViewStates.Visible : ViewStates.Gone);
expo.SetViewStubVisibilityAndInflate(this, expoVis);
var custom = view.FindViewById(Resource.Id.CurveTypeCustom);
var customVis = (ViewModel.Values.CurveType == ServoCurveType.Custom ? ViewStates.Visible : ViewStates.Gone);
custom.SetViewStubVisibilityAndInflate(this, customVis);
}