【问题标题】:Xamarin.Android - Custom RecyclerView with grouping headerXamarin.Android - 具有分组标题的自定义 RecyclerView
【发布时间】:2017-08-28 10:07:03
【问题描述】:

我想创建一个自定义 recyclerView 以具有分组部分。

我将 Xamarin.Android 与 MVVMCross 一起使用,我看到 this repo 制作了一个带有 Grouping 的 RecyclerView。

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

我做了这个简单的页面:

<?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 ---> Java.Lang.ClassNotFoundException: 在路径上找不到类“android.view.MvxRecyclerView”: DexPathList[[zip 文件“/data/app/com.companyname.AndroidApp-1/base.a…}

{Java.Lang.ClassNotFoundException: 找不到类 路径上的“android.view.MvxRecyclerView”:DexPathList[[zip 文件 "/data/app/com.companyname.AndroidApp-1/base.apk"],nativeLibraryDirectories=[/data/app/com.companyname.AndroidApp-1/lib/arm64, /data/app/com.compa…}

感谢您的帮助

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

{System.NullReferenceException:对象引用未设置为 对象的实例。在 MvvmCross.Platform.Mvx.Resolve[TService] () [0x00006] 在 C:\projects\mvvmcross\MvvmCross\Platform\Platform\Mvx.cs:33 在 MvvmCross.Binding.Droid.BindingContext.MvxAndroidBindingContextHelpers.Current[T] () [0x00000] 在 C:\projects\mvvmcross\MvvmCross\Binding\Droid\BindingContext\MvxAndroidBindingContextHelpers.cs:23 在 MvvmCross.Binding.Droid.BindingContext.MvxAndroidBindingContextHelpers.Current () [0x00000] 在 C:\projects\mvvmcross\MvvmCross\Binding\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 上下文,Android.Util.IAttributeSet attrs) [0x00000] 在 /Users/Projects/AndroidApp/AndroidApp/Controls/MvxRecyclerView.cs:16 在(包装动态方法) System.Object:1d68a509-a758-45e2-be4d-f4a51a401ff5 (intptr,object[])
在 Java.Interop.TypeManager.n_Activate (System.IntPtr jnienv, System.IntPtr jclass,System.IntPtr typename_ptr,System.IntPtr signature_ptr,System.IntPtr 作业,System.IntPtr 参数_ptr) [0x000de] 在 :0 }

【问题讨论】:

  • 从未收到此错误,但发现类似this one

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


【解决方案1】:

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

你应该添加这样的东西:

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

【讨论】:

  • 好的,用命名空间修复,但现在我有这个错误(查看我的原始帖子)
  • 尝试“清理”和“重建”项目。这帮助我解决了类似的错误。
  • 那么你的 MvxRecyclerAdapter 是什么样子的?
  • @Martijn00 我可以分享我的项目:ufile.io/i9gnu MvxRecyclerAdapter 由 TheFex 制作:github.com/thefex/MvvmCross/blob/…
  • 不要使用这样的下载网站。要么把它放在 Github 上,但最好只在此处包含代码。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多