Share via

Cannot Use RecyclerView in .NET Android MAUI

Nathan Sokalski 4,111 Reputation points
2024-10-23T20:05:49.73+00:00

With the ended support of Xamarin, I am working on converting my Xamarin.Android app to .NET Android MAUI (my app is Android only). In my xml layout file(s), I am able to use androidx.recyclerview.widget.RecyclerView without any complaints from Visual Studio 2022, but in my *.cs file(s), I am unable to use RecyclerView or any related classes. If I add the following using statement:

using AndroidX.RecyclerView.Widget;

Visual Studio 2022 give the following error:

The type or namespace name 'RecyclerView' does not exist in the namespace 'AndroidX' (are you missing an assembly reference?)

Intellisense suggests that I install the package Xamarin.AndroidX.RecyclerView, but the goal is to NOT use Xamarin, so I know this is not the correct solution. What am I forgetting or what do I need to do in order to use RecyclerView in .NET Android MAUI?

Developer technologies | .NET | .NET MAUI

1 answer

Sort by: Most helpful
  1. Graham McKechnie 451 Reputation points
    2024-10-23T22:24:12.0633333+00:00

    You seem confused by the term Xamarin when it comes to .NET Android.

    The using statement in your fragment containing a RecyclerView is

    using AndroidX.RecyclerView.Widget;

    You can then declare in your Fragment

    private RecyclerView? recyclerView;

    The AndroidX.RecyclerView.Widget is contained within Xamarin.AndroidX.Recyclerview Nuget package. The term Xamarin hasn't been removed from the Nuget packages. So it should be Xamarin.AndroidX.RecyclerView. Usually, though, some other previous Nuget package will have been installed, which already transitively references Xamarin.AndroidX.RecyclerView. For instance, if you have already installed Xamarin.AndroidX.Navigation.UI or Xamarin.AndroidX.Preference, then Xamarin.AndroidX.RecyclerView will already be available.

    If you just want Xamarin.AndroidX.RecyclerView, then search for it with the Nuget package manager.

    Jonathan Pobst (jpobst) summed it up well yesterday on Discord - DotNetEvolution #android

    when he said

    • Xamarin.Android -> .NET for Android
    • Xamarin.Forms -> MAUI Xamarin" was already confusing because, to some people, it meant "Xamarin.Android"/"Xamarin.iOS" and to others, it meant "Xamarin.Forms" unfortunately, we cannot change the NuGet package names as they will break the whole ecosystem, so they still say "Xamarin" even though they are .NET for Android/MAUI packages

    I hope the above helps you.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.