Hello,
Welcome to our Microsoft Q&A platform!
Many of my scenarios involve editing and/or navigating data that is saved in collections & arrays and accessed by index
How can I easily access not currently visible items by index and/or know how & when to wait for them?
We can only edit or navigate the item on the UI when the item is visible. Of cource, we can also edit the data in code-behind and call the following code in your RecyclerView.Adapter
to update the UI once the item is visible.
NotifyDataSetChanged();
For example, we can edit the datalist filled into the RecyclerView in our activity like this:
private void updateData() {
Photo item = datalist[0]; // loadBranch is my datalist Photo is my model of data list
item.mCaption = "updated value"; // mCaption is a field of my item
mAdapter.UpDateData(datalist );//mAdapter is my RecyclerView's adapter
}
method UpDateData
is a method of my RecyclerView.Adapter
public class PhotoAlbumAdapter: RecyclerView.Adapter
{
public List<Photo> mPhotoAlbum = new List<Photo>();
public RecyclerView.Adapter adapter;
public PhotoAlbumAdapter(List<Photo> branchesList)
{
adapter = this;
mPhotoAlbum = branchesList;
}
public override void OnViewRecycled(Java.Lang.Object holder)
{
base.OnViewRecycled(holder);
PhotoViewHolder holder1 = holder as PhotoViewHolder;
}
public void UpDateData(List<Photo> temp)
{
mPhotoAlbum = temp;
NotifyDataSetChanged();
}
// other code
}
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.