0

I'm developing an application in Xamarin for Android which needs to get a list of calendars. I've found an example how to do it but there is used CursorLoader which is mark as deprecated. I wasn't able to find a replacement of the function in Xamarin. Is there an another way how to get list of calendars? Thanks.

AndroidCalendarModels _androidCalendarModel = new AndroidCalendarModels();
            string[] calendarsProjection = {
                CalendarContract.Calendars.InterfaceConsts.Id,
                CalendarContract.Calendars.InterfaceConsts.CalendarDisplayName,
                CalendarContract.Calendars.InterfaceConsts.AccountName 
                };

            var calendarsUri = CalendarContract.Calendars.ContentUri;            
            var loader = new CursorLoader(Android.App.Application.Context, calendarsUri, calendarsProjection, null, null, null);
            var cursor = (ICursor)loader.LoadInBackground();

            while (cursor.MoveToNext())
            {
                int calId = cursor.GetInt(0);
                string calName = cursor.GetString(1);
                string calAccount = cursor.GetString(2);

                _androidCalendarModel.Calendars.Add(new AndroidCalendarModel()
                {
                    Id = calId,
                    AccountName = calAccount,
                    CalendarDisplayName = calName,
                });
            }
  • Where do you use BearsorLoader? I can only see that you are using CursorLoader. Can you provide more relevant code?I will first provide you with a link to this document, and I hope it will help you:"https://learn.microsoft.com/en-us/xamarin/android/user-interface/controls/calendar". – Hongxin Sui-MSFT Oct 07 '22 at 02:08
  • I'm not speaking about BearsonLoader, I ment only Cursor loader... The link you provided I used for building my code already, I only do not use ListAdapter but mapping to my own structure. – Libor Foltynek Oct 07 '22 at 06:15
  • May I know what your own structure is, or can you point out its specific code? – Hongxin Sui-MSFT Oct 10 '22 at 06:43

0 Answers0