ClassNotFoundException Mvx.MvxListView [英] ClassNotFoundException Mvx.MvxListView

查看:72
本文介绍了ClassNotFoundException Mvx.MvxListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将MvxListViewMvxAppCompatActivity一起使用,但我总是得到:

I'm trying use MvxListView with MvxAppCompatActivity, but I always get:

InflateException:膨胀类Mvx.MvxListView时出错 ClassNotFoundException:找不到类"Mvx.MvxListView

InflateException: Error inflating class Mvx.MvxListView ClassNotFoundException: Didn't find class "Mvx.MvxListView

这是我的axml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res/com.viniciusmaia.missaocarona"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <include
        layout="@layout/Toolbar" />

    <Mvx.MvxListView
        android:id="@+id/teste"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        app:MvxBind="ItemsSource Usuarios;ItemClick UsuarioClickCommand"
        app:MvxItemTemplate="@layout/usuarioitem"/>
</LinearLayout>

这是我的活动:

[Activity] 
public class UsuarioActivity : MvxAppCompatActivity<UsuarioViewModel>
{
    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);

        SetContentView(Resource.Layout.UsuarioView);            

        var toolbar = FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);

        toolbar.Title = UsuarioMensagens.TITULO_Usuario;

        //SetSupportActionBar(toolbar);

        Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);

        ViewModel.Carregamento = new Carregamento(this);
        ViewModel.PreenchePagina();
    }
}

我尝试使用Mvx.MvxListviewMvxListView这样的帖子

I tried use Mvx.MvxListview and MvxListView like this post Binary XML file line #1: Error inflating class Mvx.MvxListView, but nothing works for me.

有人可以帮助我吗?

推荐答案

Mvx.MvxListView是在自定义Inflater中注册的快捷方式,该自定义Inflater在MvvmCross中进行绑定.这意味着,如果您的Setup类不告诉您在哪里寻找Mvx,则快捷方式将无效.

Mvx.MvxListView mentioned in Alex's answer is a shortcut that is registered with the custom Inflater that does binding in MvvmCross. This means, if your Setup class does not tell where to look for Mvx, the shortcuts wont work.

在这种情况下,我看到您正在使用MvxAppCompatActivity,它来自一个支持软件包.您可以从那里继承一个单独的安装程序,该程序可以为您处理大量注册.它还将设置一些可识别色彩的视图.

In this case, I see you are using MvxAppCompatActivity, which comes from one of the Support packages. There is a separate Setup you inherit from there, which handles a lot of registration for you. It will also set up some tint aware views.

因此,在您的设置中,您应该从 MvxAppCompatSetup :

So in your Setup, you should inherit from MvxAppCompatSetup:

public class Setup : MvxAppCompatSetup
{
}

这应该足以找到Mvx.MvxListView.如果不是,您可以尝试通过覆盖设置中的ViewNamespaceAbbreviations来添加更多缩写:

This should be enough to find Mvx.MvxListView. If it doesn't you can try adding more abbreviations by overriding ViewNamespaceAbbreviations in your Setup:

public class Setup : MvxAppCompatSetup
{
    ...

    protected override IDictionary<string, string> ViewNamespaceAbbreviations new Dictionary<string, string>
    {
        {"Mvx", "MvvmCross.Binding.Droid.Views"},
        {"MyViews", "My.Custom.Views"},
        // add more abbreviations here
    };
}

当在axml文件中使用Mvx作为前缀时,这会使MvvmCross在MvvmCross.Binding.Droid.Views中寻找视图.

This will make MvvmCross look for views in MvvmCross.Binding.Droid.Views when you prefix them with Mvx in your axml files.

"Mvx" =>"MvvmCross.Binding.Droid.Views"是默认值,并且可以与MvxAppCompatSetupMvxAndroidSetup中的任何BindingInflater一起使用.

"Mvx" => "MvvmCross.Binding.Droid.Views" is a default one, and should work with any BindingInflater from both MvxAppCompatSetup, but also MvxAndroidSetup.

这篇关于ClassNotFoundException Mvx.MvxListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆