简体   繁体   English

如何从 RecyclerView 适配器访问 viewPager 适配器内的片段实例

[英]How to access fragment instance inside a viewPager adapter from a RecyclerView adapter

I have a process for creating a new restaurant.我有一个创建新餐厅的过程。 This is a 5 stage process which I built with a view pager and 5 fragments.这是一个 5 阶段的过程,我使用视图寻呼机和 5 个片段构建。

one of the fragments is for the user to upload photos of the place.其中一个片段是供用户上传该地点的照片。

My problem starts, when I want to allow users to remove certain photos.当我想允许用户删除某些照片时,我的问题就开始了。

How, from within the recyclerAdapter's instance for that photo, I can remove it from the adapter itself, which is inside a fragment in the viewPager?如何从该照片的 recyclerAdapter 实例中将其从适配器本身(位于 viewPager 的片段内)中删除? The viewPager fragments are single instances, and I can't access them, so I'm a bit lost. viewPager 片段是单个实例,我无法访问它们,所以我有点迷茫。

Your instance of RecyclerView.Adapter should have a reference to the underlying data it's diplaying eg an array or a list of photos in your case.您的 RecyclerView.Adapter 实例应该引用它正在显示的基础数据,例如在您的案例中的数组或照片列表。

The underlying data are used inside your Adapter's implementation of onBindViewHolder() to fill the RecyclerView.ViewHolder at the given position.底层数据在适配器的onBindViewHolder()实现中用于填充给定 position 处的 RecyclerView.ViewHolder。

To remove a photo, your fragment has to remove the corresponding entry in the underlying data set, then refresh the view by calling your adapter's notifyDataSetChanged()要删除照片,您的片段必须删除底层数据集中的相应条目,然后通过调用适配器的notifyDataSetChanged()刷新视图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM