MvvmCross Android – Error Inflating class Mvx.MvxBindableListView-Collection of common programming errors

I’m having trouble using an activity with MvvmCross in Mono for Android. Basically, the app compiles, and runs, but I get an unhandled exception when I call SetContentView:

“Android.Views.InflateException: Binary XML file line #1: Error inflating class Mvx.MvxBindableListView”

In the stack trace it mentions the class not found was the cause.

Here’s my Activity:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Cirrious.MvvmCross.Droid.Views;
using WshLst.Core.ViewModels;
using WshLst.Core.Models;

namespace WshLst.MonoForAndroid.Views
{
    [Activity(Label = "Wsh Lst - Login")]
    public class LoginView : MvxActivityView
    {
        ListView list;

        protected override void OnViewModelSet()
        {
            RequestWindowFeature(WindowFeatures.ActionBar);

            SetContentView(Resource.Layout.Page_LoginView);

            list = this.FindViewById(Resource.Id.mvxList);

            list.ItemClick += (s, e) =>
            {
                var item = list.Adapter.GetItem(e.Position);

                var castItem = (Cirrious.MvvmCross.Binding.Droid.MvxJavaContainer)item;

                this.ViewModel.Login((WshLst.Core.Models.LoginPlatform)castItem.Object);
            };
        }
    }
}
  1. Your activity needs to inherit from MvxBindingActivityView instead of MvxActivityView

    The back story

    MvvmCross is built in layers and modules:

    • Cirrious.MvvmCross – just gives the core INotifyPropertyChanged and navigation
    • Cirrious.MvvmCross.Binding – gives you data-binding for Droid and Touch
    • Cirrious.MvvmCross.Dialog – gives you monotouch/droid/soon more Dialog helpers
    • Cirrious.MvvmCross.AutoViews – this might one day give you automatic default UI views
    • Plugins – each plugin gives you specific functionality – e.g. SQLite

    The idea is to try to provide a “light” core framework for those who just want the bare minimum, but to provide a more sophisticated framework for those who want more.

    This does have the downside that some of the names can get confusing… that there are more dll’s to reference… and that users can occasionally inherit from the wrong level object – which is what your problem was here:

    • you were inheriting from MvxActivityView which has a ViewModel
    • but not from MvxBindingActivityView which has binding support as well.

    There’s a little more info on what’s in the 2 layers at Insert a Monogame view inside MvvmCross monodroid Activity

  2. New cause: the MvxBindableListView is renamed to MvxListView. But the above is confusing by now. Because I was inheriting from MvxFragment I thought this was the cause and was trying to understand and implement what Stuart wrote … Then I remembered something about renaming classes and then it was quickly found 🙂