Xamarin.Android - 自定义RecyclerView与分组标题

时间:2017-08-28 10:07:04

标签: c# android-recyclerview xamarin.android mvvmcross

我想创建一个自定义的recyclerView来分组。

我使用Xamarin.Android和MVVMCross,我看到this repo使用分组制作RecyclerView。

好吧,我复制了他所有的文件,并尝试编译我的解决方案(因为我必须使用MVVMCross v5.0.5):

My project

我做了这个简单的页面:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:local="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidapp.controls.MvxRecyclerView
            android:id="@+id/my_recycler_view"
            android:scrollbars="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent" 
            local:MvxItemTemplate="@layout/listitem_recyclerviewexample"
            MvxHeaderLayoutId="@layout/recyclerviewexample_header"
            MvxFooterLayoutId="@layout/recyclerviewexample_footer"
            MvxHidesHeaderIfEmpty="true"
            MvxHidesFooterIfEmpty="true"
            local:MvxBind="ItemsSource Items; ItemClick ItemSelected"/>


</LinearLayout>

但是当我的页面显示时出现此错误:

  

{Android.Views.InflateException:二进制XML文件行#1:错误   膨胀类MvxRecyclerView ---&gt;抛出java.lang.ClassNotFoundException:   没找到课程&#34; android.view.MvxRecyclerView&#34;在路径上:   DexPathList [[zip file&#34; /data/app/com.companyname.AndroidApp-1/base.a ...}}

  

{Java.Lang.ClassNotFoundException:没找到课程   &#34; android.view.MvxRecyclerView&#34;在路径上:DexPathList [[zip文件   &#34; /data/app/com.companyname.AndroidApp-1/base.apk"],nativeLibraryDirectories = [/数据/应用/ com.companyname.AndroidApp-1 / LIB / arm64,   /data/app/com.compa...}

感谢您的帮助

编辑:现在我有这个错误(我更新了我的axml代码):

  

{System.NullReferenceException:对象引用未设置为   对象的实例。在MvvmCross.Platform.Mvx.Resolve [TService]   ()[0x00006] in   C:\ projects \ mvvmcross \ MvvmCross \ Platform \ Platform \ Mvx.cs:33 at   MvvmCross.Binding.Droid.BindingContext.MvxAndroidBindingContextHelpers.Current [T]   ()[0x00000] in   C:\项目\ mvvmcross \ MvvmCross \装订\ Droid的\的BindingContext \ MvxAndroidBindingContextHelpers.cs:23   在   MvvmCross.Binding.Droid.BindingContext.MvxAndroidBindingContextHelpers.Current   ()[0x00000] in   C:\项目\ mvvmcross \ MvvmCross \装订\ Droid的\的BindingContext \ MvxAndroidBindingContextHelpers.cs:17   在AndroidApp.Controls.MvxRecyclerAdapter..ctor()[0x00000]中   /Users/Projects/AndroidApp/AndroidApp/Controls/MvxRecyclerAdapter.cs:34   在AndroidApp.Controls.MvxRecyclerView..ctor(Android.Content.Context   context,Android.Util.IAttributeSet attrs)[0x00000] in   /Users/Projects/AndroidApp/AndroidApp/Controls/MvxRecyclerView.cs:16   at(包装器动态方法)   System.Object:1d68a509-a758-45e2-be4d-f4a51a401ff5(intptr,object [])
  at Java.Interop.TypeManager.n_Activate(System.IntPtr jnienv,   System.IntPtr jclass,System.IntPtr typename_ptr,System.IntPtr   signature_ptr,System.IntPtr jobject,System.IntPtr parameters_ptr)   [0x000de] in:0}

1 个答案:

答案 0 :(得分:2)

它说Didn't find class "android.view.MvxRecyclerView",但实际位置不同。您可以将您的命名空间或MvvmCross添加到Setup.cs中的AndroidViewAssemblies。

您应该添加以下内容:

protected override IEnumerable<Assembly> AndroidViewAssemblies => new 
List<Assembly>(base.AndroidViewAssemblies)
{
    typeof(MvxRecyclerView).Assembly
};
相关问题