【问题标题】:Xamarin AndroidX RecyclerView AdapterXamarin AndroidX RecyclerView 适配器
【发布时间】:2020-04-02 01:35:54
【问题描述】:

嗨,我是 Xamarin Android 开发的新手,我已经成功地将我的应用程序迁移到 AndroidX,没有任何错误,但是当我添加 RecyclerView Adapter 时,它给了我一堆错误。任何帮助深表感谢。谢谢

重现步骤:

  1. 在 Nuget 中添加了 Xamarin AndroidX 包
  2. 添加 RecyclerView 适配器

这是我的包裹:

<PackageReference Include="Xamarin.Android.Support.Design" Version="28.0.0.3" />
    <PackageReference Include="Xamarin.Android.Support.Core.Utils" Version="28.0.0.3" />
    <PackageReference Include="Xamarin.Android.Support.CustomTabs" Version="28.0.0.3" />
    <PackageReference Include="Xamarin.AndroidX.Annotation">
      <Version>1.1.0</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.AndroidX.AppCompat">
      <Version>1.1.0</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.AndroidX.Browser">
      <Version>1.2.0</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.AndroidX.CardView">
      <Version>1.0.0</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.AndroidX.Lifecycle.LiveData">
      <Version>2.2.0</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.AndroidX.Media">
      <Version>1.1.0</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.AndroidX.MediaRouter">
      <Version>1.1.0</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.AndroidX.Migration">
      <Version>1.0.2</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Essentials" Version="1.3.1" />
    <PackageReference Include="Xamarin.Firebase.Auth">
      <Version>60.1142.1</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Firebase.Common">
      <Version>60.1142.1</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Firebase.Database">
      <Version>60.1142.1</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Google.Android.Material">
      <Version>1.0.0</Version>
    </PackageReference>

这是我的错误:

Severity    Code    Description Project File    Line    Suppression State
Error   CS0518  Predefined type 'System.Object' is not defined or imported  ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 30  Active
Error   CS1503  Argument 2: cannot convert from 'method group' to 'Action<StorelistAdapterClickEventArgs>'  ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 30  Active
Error   CS0246  The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)    ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 1   Active
Error   CS0246  The type or namespace name 'Android' could not be found (are you missing a using directive or an assembly reference?)   ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 3   Active
Error   CS0246  The type or namespace name 'Android' could not be found (are you missing a using directive or an assembly reference?)   ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 4   Active
Error   CS0246  The type or namespace name 'Android' could not be found (are you missing a using directive or an assembly reference?)   ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 5   Active
Error   CS0246  The type or namespace name 'RecyclerView' could not be found (are you missing a using directive or an assembly reference?)  ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 9   Active
Error   CS0518  Predefined type 'System.Object' is not defined or imported  ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 11  Active
Error   CS0246  The type or namespace name 'EventHandler<>' could not be found (are you missing a using directive or an assembly reference?)    ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 11  Active
Error   CS0518  Predefined type 'System.Object' is not defined or imported  ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 11  Active
Error   CS0518  Predefined type 'System.Void' is not defined or imported    ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 11  Active
Error   CS0518  Predefined type 'System.Void' is not defined or imported    ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 11  Active
Error   CS0518  Predefined type 'System.Object' is not defined or imported  ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 12  Active
Error   CS0246  The type or namespace name 'EventHandler<>' could not be found (are you missing a using directive or an assembly reference?)    ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 12  Active
Error   CS0518  Predefined type 'System.Object' is not defined or imported  ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 12  Active
Error   CS0518  Predefined type 'System.Void' is not defined or imported    ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 12  Active
Error   CS0518  Predefined type 'System.Void' is not defined or imported    ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 12  Active
Error   CS0518  Predefined type 'System.String' is not defined or imported  ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 13  Active
Error   CS0518  Predefined type 'System.Void' is not defined or imported    ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 15  Active
Error   CS0518  Predefined type 'System.String' is not defined or imported  ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 15  Active
Error   CS0518  Predefined type 'System.Object' is not defined or imported  ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 21  Active
Error   CS0246  The type or namespace name 'RecyclerView' could not be found (are you missing a using directive or an assembly reference?)  ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 21  Active
Error   CS0518  Predefined type 'System.Object' is not defined or imported  ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 21  Active
Error   CS0246  The type or namespace name 'ViewGroup' could not be found (are you missing a using directive or an assembly reference?) ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 21  Active
Error   CS0518  Predefined type 'System.Int32' is not defined or imported   ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 21  Active
Error   CS0518  Predefined type 'System.Void' is not defined or imported    ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 35  Active
Error   CS0518  Predefined type 'System.Object' is not defined or imported  ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 35  Active
Error   CS0246  The type or namespace name 'RecyclerView' could not be found (are you missing a using directive or an assembly reference?)  ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 35  Active
Error   CS0518  Predefined type 'System.Int32' is not defined or imported   ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 35  Active
Error   CS0518  Predefined type 'System.Int32' is not defined or imported   ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 44  Active
Error   CS0115  'StorelistAdapter.ItemCount': no suitable method found to override  ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 44  Active
Error   CS0518  Predefined type 'System.Void' is not defined or imported    ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 46  Active
Error   CS0518  Predefined type 'System.Object' is not defined or imported  ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 46  Active
Error   CS0518  Predefined type 'System.Void' is not defined or imported    ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 47  Active
Error   CS0518  Predefined type 'System.Object' is not defined or imported  ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 47  Active
Error   CS0246  The type or namespace name 'RecyclerView' could not be found (are you missing a using directive or an assembly reference?)  ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 51  Active
Error   CS0518  Predefined type 'System.Void' is not defined or imported    ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 56  Active
Error   CS0518  Predefined type 'System.Object' is not defined or imported  ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 56  Active
Error   CS0246  The type or namespace name 'View' could not be found (are you missing a using directive or an assembly reference?)  ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 56  Active
Error   CS0518  Predefined type 'System.Object' is not defined or imported  ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 56  Active
Error   CS0246  The type or namespace name 'Action<>' could not be found (are you missing a using directive or an assembly reference?)  ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 56  Active
Error   CS0518  Predefined type 'System.Object' is not defined or imported  ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 56  Active
Error   CS0518  Predefined type 'System.Object' is not defined or imported  ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 57  Active
Error   CS0246  The type or namespace name 'Action<>' could not be found (are you missing a using directive or an assembly reference?)  ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 57  Active
Error   CS0518  Predefined type 'System.Object' is not defined or imported  ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 57  Active
Error   CS0246  The type or namespace name 'EventArgs' could not be found (are you missing a using directive or an assembly reference?) ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 65  Active
Error   CS0518  Predefined type 'System.Object' is not defined or imported  ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 67  Active
Error   CS0246  The type or namespace name 'View' could not be found (are you missing a using directive or an assembly reference?)  ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 67  Active
Error   CS0518  Predefined type 'System.Void' is not defined or imported    ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 67  Active
Error   CS0518  Predefined type 'System.Int32' is not defined or imported   ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 68  Active
Error   CS0518  Predefined type 'System.Void' is not defined or imported    ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 68  Active
Error   CS0518  Predefined type 'System.Object' is not defined or imported  ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 25  Active
Error   CS0246  The type or namespace name 'View' could not be found (are you missing a using directive or an assembly reference?)  ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 25  Active
Error   CS0518  Predefined type 'System.Object' is not defined or imported  ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 30  Active
Error   CS0518  Predefined type 'System.Object' is not defined or imported  ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 30  Active
Error   CS1503  Argument 3: cannot convert from 'method group' to 'Action<StorelistAdapterClickEventArgs>'  ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 30  Active
Error   CS0518  Predefined type 'System.Object' is not defined or imported  ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 40  Active
Error   CS0518  Predefined type 'System.Array' is not defined or imported   ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 44  Active
Error   CS0518  Predefined type 'System.Object' is not defined or imported  ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 44  Active
Error   CS1061  'string[]' does not contain a definition for 'Length' and no accessible extension method 'Length' accepting a first argument of type 'string[]' could be found (are you missing a using directive or an assembly reference?)    ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 44  Active
Error   CS1729  'RecyclerView.ViewHolder' does not contain a constructor that takes 1 arguments ApplicationName C:\Users\SuperUser\source\repos\ApplicationName\ApplicationName\Adapter\StorelistAdapter.cs 57  Active

【问题讨论】:

    标签: firebase xamarin android-recyclerview package androidx


    【解决方案1】:

    首先,请确保您已经安装了这些 nuget 包。

    请检查以下地方。

    1. 打开你的Adapter.cs,注意RecyclerView.Adapter的命名空间,正确的命名空间是AndroidX.RecyclerView.Widget

    1. layout.xml 中RecyclerView 的命名空间,在Android X 中,应更改为androidx.recyclerview.widget.RecyclerView,如下代码所示。
    <androidx.recyclerview.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent" 
        android:id="@+id/recyclerView1"/>
    
    1. 请打开你的Activiy.cs,你的包命名空间LinearLayoutManagerRecyclerViewAndroidX.RecyclerView.Widget

    这是我运行 Android Q 的应用程序的 GIF。

    这是我的演示。

    https://github.com/851265601/XAndroidX

    【讨论】:

    • 嗨,Leon,尝试了你的演示,它工作正常。但是,当我添加 firebase 和 googleplayservices 时,它会重新出现。我猜这些包之间存在冲突。 imgur.com/wJzgBCg
    • 请关闭你的VS,然后打开你的项目文件夹;删除binobj文件夹;重新打开您的项目并构建它之后。
    • 这让我免于头疼。谢谢大佬,不胜感激。
    • 请不要忘记标记这个答案(点击这个答案右上角的☑️),它将帮助有类似问题的其他人。
    猜你喜欢
    • 2021-04-24
    • 1970-01-01
    • 2016-04-08
    • 2021-06-03
    • 2019-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多