gpt4 book ai didi

android - Kotlin:如何在 RecyclerView.Adapter 中调用 getSupportFragmentManager()

转载 作者:行者123 更新时间:2023-12-04 23:56:41 27 4
gpt4 key购买 nike

我想在单击事件后调用我的 RecyclerView.Adapter 中的支持 fragment 管理器,以便移动到不同的 fragment 。我的做法:

(context as MainActivity).supportFragmentManager
.beginTransaction()
.replace(MainActivity.FRAGMENT_CONTAINER, TextScreen())
.commit()

但是我得到以下错误:

kotlin.TypeCastException: null cannot be cast to non-null type

你能帮帮我吗?

最佳答案

2021 年更新 - Kotlin Answer

If you want to call "supportFragmentManager" in Fragment

activity.supportFragmentManager

关于android - Kotlin:如何在 RecyclerView.Adapter 中调用 getSupportFragmentManager(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54009730/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com