简体   繁体   English

从第二个Fragment的recyclerView中选择项目时如何切换到第一个Fragment? 两个片段都在带有 viewPager2 的 tablayout 中

[英]How to switch to the first fragment when selecting an item from the recyclerView of second Fragment? Both fragments are in tablayout with viewPager2

强文本

When I click an item from the SongList fragment, it should automatically switch to the NowPlaying fragment.当我从 SongList 片段中单击一个项目时,它应该会自动切换到 NowPlaying 片段。 Also how will I send the item position of the selected song from the recyclerView of the SongList fragment to the NowPlaying fragment?另外,我如何将所选歌曲的项目 position 从 SongList 片段的 recyclerView 发送到 NowPlaying 片段? Thanks.谢谢。

Access your NavController in your Fragment with getParentFragmentManager().findFragmentById(R.id.fragment_container_view) and call .navigate(R.id.now_playing) .使用getParentFragmentManager().findFragmentById(R.id.fragment_container_view)访问 Fragment 中的 NavController 并调用.navigate(R.id.now_playing)

暂无
暂无

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

相关问题 当在TabLayout中调用其他片段时,第一个片段出现第二秒钟 - First fragment appears for a second when other fragments are called in tablayout 我在viewpager中有布局,如何在第一个片段以外的4个片段中隐藏Bottombar? - I have tablayout with viewpager how to hide Bottombar in 4 Fragments except first Fragment? 想要使用浮动操作按钮将项目添加到 ViewPager2 中包含的特定片段中的回收视图 - Want to use a floating action button that adds an item to a recyclerview in a specific fragment that is contained in a ViewPager2 如何通过从片段上的recyclerView中选择一项来执行操作 - how to perform an action by selecting an item from the recyclerView on the fragment 选择不同的选项卡时如何在 ViewPager + TabLayout 中暂停片段? - How to pause a fragment in ViewPager + TabLayout when a different tab is selected? 带有带有recyclerview的选项卡片段的viewpager仅显示数据库中的第一项 - viewpager with tab fragments with recyclerview just show first item from database Viewpager中的片段只有在旁边的片段打开时才会刷新 - Fragment in Viewpager only refreshing when it's open from fragments next to it 如何将数据从对话片段发送到Viewpager中的所有片段? - How to send data from a dialogue fragment to all fragments within a Viewpager? 在片段的viewpager中,如何请求将数据从一个片段拉到另一个片段 - In a viewpager of fragments, how to request to pull data from one fragment to another 将带有片段的 Tablayout 作为子片段嵌套在导航抽屉中的片段内 - Nesting a Tablayout With Fragments as Child fragments inside an Fragment from Navigation drawer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM