Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DataBindings are broken after update to MvvmCross 4.0 when using AppCompatActivity

I'm using the android toolbar at my MvvmCross 3.5.1 app but once I updated it to MvvmCross 4.0 databindings are broken. As long as there is no base appcompat activity I have to implement my own:

MvxActionBarEventSourceActivity : AppCompatActivity , IMvxEventSourceActivity
{
 ...
}

And then base bindable mvx activity:

MvxActionBarActivity : MvxActionBarEventSourceActivity, IMvxAndroidView
{
 ...
}

App starts just fine and I can see my toolbar but bindings are just "silent" and don't work. Same implementation works find for MvvmCross 3.5.

You can find full sample here: https://dl.dropboxusercontent.com/u/19503836/MvvmCross4_Toolbar_Bindings.zip

Please advise.

like image 672
Alexey Strakh Avatar asked Feb 27 '16 02:02

Alexey Strakh


1 Answers

You need to override OnCreateView and AttachBaseContext and use the MvxAppCompatActivityHelper to support bindings: https://github.com/MvvmCross/MvvmCross-AndroidSupport/blob/master/MvvmCross.Droid.Support.V7.AppCompat/MvxAppCompatActivity.cs#L78

    public override View OnCreateView(View parent, string name, Context context, IAttributeSet attrs)
    {
        var view = MvxAppCompatActivityHelper.OnCreateView(parent, name, context, attrs);
        return view ?? base.OnCreateView(parent, name, context, attrs);
    }

    protected override void AttachBaseContext(Context @base)
    {
        base.AttachBaseContext(MvxContextWrapper.Wrap(@base, this));
    }

There is a sample available to implement Toolbar instead of Actionbar too: https://github.com/MvvmCross/MvvmCross-AndroidSupport/tree/master/Samples

like image 165
Martijn00 Avatar answered Sep 22 '22 19:09

Martijn00