question

njsokalski avatar image
0 Votes"
njsokalski asked RobCaplan edited

NotifyItemInserted Not Working On Emulator

I have a RecyclerView (rvRoundNumbers) that I update using the following code:

 (this.rvRoundNumbers.GetAdapter() as RoundNumbersAdapter).RoundNumbers.Add(this.rvRoundNumbers.GetAdapter().ItemCount + 1);
 this.rvRoundNumbers.GetAdapter().NotifyItemInserted(this.rvRoundNumbers.GetAdapter().ItemCount - 1);

I have tried debugging this on my Surface Duo, the Surface Duo emulator, and an emulator in Visual Studio 2019. When using my Surface Duo & the Surface Duo emulator, it works fine (the RecyclerView is updated & I see the new data), but the emulator does not seem to update the RecyclerView (it does not display the added item). Is this a problem with the emulator? Is there some difference in Surface Duo that would cause it to work differently for this? Any help would be appreciated, thanks.

dotnet-xamarin
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @njsokalski ,I have not heard from you for a couple of days. Please let me know if there is anything that I can help here.

0 Votes 0 ·

1 Answer

JessieZhang-2116 avatar image
0 Votes"
JessieZhang-2116 answered

Hello,


Welcome to our Microsoft Q&A platform!

I did a test on my side, but I couldn't reproduce this problem. Could you please post a basic demo to github or onedriver so that we can test on our side?

But you can also try the following method which also works on my android Emulator.

  1. add a function(e.g. insert) on your adapter. you can refer the following code:

          public void insert(Photo item) {
             mPhotoAlbum.Add(item);
             NotifyDataSetChanged();
         }
    

2.In you activity:

         mInsertBtn.Click += delegate{
             Photo item = new Photo
             {
                 mPhotoID = Resource.Drawable.buckingham_guards,
                 mCaption = "a new item22",
                 isChecked = false
             };
             mAdapter.insert(item);

        // (this.mRecyclerView.GetAdapter() as PhotoAlbumAdapter).mPhotoAlbum.Add(item);
         //mRecyclerView.GetAdapter().NotifyItemInserted(this.mRecyclerView.GetAdapter().ItemCount-1);

         };

Best Regards,


Jessie Zhang


If the response is helpful, please click "Accept Answer" and upvote it.



Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.