Xamarin AndroidX RecyclerView Адаптер - PullRequest
0 голосов
/ 02 апреля 2020

Привет, я новичок в разработке Xamarin Android, и я успешно перенес свое приложение на AndroidX без каких-либо ошибок, но когда я добавляю RecyclerView Adapter, это выдает мне кучу ошибок. Буду признателен за любую оказанную помощь. Спасибо

Шаги для воспроизведения:

  1. Добавлены пакеты Xamarin AndroidX в Nuget
  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

1 Ответ

1 голос
/ 02 апреля 2020

Прежде всего, пожалуйста, убедитесь, что вы установили эти пакеты nuget.

enter image description here

И, пожалуйста, проверьте следующие места.

  1. Откройте ваш Adapter.cs, обратите внимание на пространство имен RecyclerView.Adapter, правильное пространство имен - AndroidX.RecyclerView.Widget

enter image description here

Пространство имен RecyclerView в макете. xml, В Android X, оно должно быть изменено androidx.recyclerview.widget.RecyclerView, как показано в следующем коде.
<androidx.recyclerview.widget.RecyclerView
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:id="@+id/recyclerView1"/>
Пожалуйста, откройте ваш Activiy.cs, пространство имен вашего пакета LinearLayoutManager и RecyclerView AndroidX.RecyclerView.Widget

Вот GIF-файл моего приложения, работающего Android Q.

enter image description here

Вот мое демо.

https://github.com/851265601/XAndroidX

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...