如何通过单击底部纸内部的按钮来替换底部纸的外部片段?

发布于 2025-02-12 02:11:42 字数 1037 浏览 1 评论 0原文

因此,我决定将我的应用程序带有单个活动。在我的一个片段(fragment(a))中,我打开底部表通过单击按钮打开BS。现在,棘手的公园,底部的底表内有一个fragmentContainerview,其中有两个片段,我想单击此button B内部fragmentContainerview(在fragment(b))将将fragment(a)更改为 fragment(c)和关闭底部表。

我知道,通过下面使用代码,可以交换片段和关闭底部表(在这里,我在fragmentContainerview的外部单击按钮,但仍在底部表中):

ButtonSH.setOnClickListner{
    parentFragmentManager.commit {
          // replace fragment
          replace<FragmentC>(R.id.fragment_container_that_holds_fragmets_A_and_C)
    }
    // close bottom sheet
    dismiss()
}

但是我只是不明白如何了解通过单击按钮bfragmentContainerview in fragment(b)中进行同样的操作。

如果重要的话,fragment(a)不直接在活动中,它在其他一些片段中。

这是一个可以更好地理解的图像:

”可视化,以更好地理解”

So I've decided to make my app with single Activity. In one of my fragments (fragment(A)) I open bottom sheet by clicking Button open BS. Now the tricky park, inside bottom sheet there is a FragmentContainerView that has two fragments inside and I want to click Button B inside this FragmentContainerView (in fragment(B)) that would change fragment(A) to fragment(C) and close bottom sheet.

I'm aware that by using code below it's possible to swap fragment and close bottom sheet (here I'm clicking button outside of FragmentContainerView but still inside bottom sheet):

ButtonSH.setOnClickListner{
    parentFragmentManager.commit {
          // replace fragment
          replace<FragmentC>(R.id.fragment_container_that_holds_fragmets_A_and_C)
    }
    // close bottom sheet
    dismiss()
}

But I just can't understand how to do the same by clicking Button B inside FragmentContainerView in fragment(b).

If it matters, fragment(A) is not directly inside activity, it is inside a few other fragments.

Here is an image for better understanding:

visualisation for better understanding

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风铃鹿 2025-02-19 02:11:42

因此,我的解决方案是为底部纸及其片段制作共享视图模型,并为容器中使用另一个共享视图模型,该容器容纳片段(a)和底部纸。我观察到ViewModels内部的变量以替换片段。有关正式文档,请访问 this

So my solution was to make sharedViewModel for bottom sheet and its fragments, and to use another sharedViewModel for container that holds fragment(A) and for bottom sheet. I observe variables inside viewModels to replace fragments. For official documentation visit this

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文