简体   繁体   中英

RecyclerView.ViewHolder communicating with Fragment

I need to find a way for a recyclerview to tell a fragment when a certain type of post is shown on the screen. I'm having trouble developing a generalized method for determining if and how many video posts are shown on the screen at any given point in time. What I want is for the fragment to at least know when a video post (along with their state) is on the screen so that the activity can become unlocked from portrait mode so that on rotation the VideoView takes up the entire screen instead of a small part of it (assuming the video is playing). Given the situation where there is more than one video post shown, when one is started while the other is playing, I want the one playing to stop and the other video post to start playing. The logic for controlling video playback is in the viewholder class. How would I go about setting up this functionality?

Using a interface was the way to go. I also looked up EventBus, but apparently those types of mechanisms are used for when you have one component sending messages to multiple recipients (as opposed to when you implement a listener, which is for a one to one connection).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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