Search code examples
firebasexamarinandroid-recyclerviewpackageandroidx

Xamarin AndroidX RecyclerView Adapter


Hi Im new in Xamarin Android development and I've successfully migrated my application to AndroidX without any errors, but when i Add RecyclerView Adapter it gives me a bunch of errors. Any help is much appreciated. Thanks

Steps to reproduce:

  1. Added Xamarin AndroidX packages in Nuget
  2. Adding RecyclerView Adapter

Here's my packages:

<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>

And Heres my Error:

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

Solution

  • First of all, please make sure you have install these nuget packages.

    enter image description here

    And please check the following places.

    1. Open your Adapter.cs, please notice the namespace of RecyclerView.Adapter, the correct namespace is AndroidX.RecyclerView.Widget

    enter image description here

    1. Namespace of the RecyclerView in layout.xml, In Android X, it should be changed androidx.recyclerview.widget.RecyclerView like following code.
    <androidx.recyclerview.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent" 
        android:id="@+id/recyclerView1"/>
    
    1. Please Open your Activiy.cs, you package namespace of LinearLayoutManager and RecyclerView are AndroidX.RecyclerView.Widget

    Here is GIF of my application running Android Q.

    enter image description here

    Here is my demo.

    https://github.com/851265601/XAndroidX