如何通过单击刚打开的片段来防止打开新片段?

发布于 2025-02-02 11:40:24 字数 1068 浏览 2 评论 0原文

我使用RecyClerview创建了项目的网格。当用户单击该项目时,全屏片段将打开。它运行良好。但是,当用户单击任何全屏片段表面时,我看到了循环网格电网打开的新片段时的奇怪情况。事实证明,用户(按原样)点击片段下的按钮。如何避免这种情况?

这是密码的一部分,如何组织点击聆听:

SetGrid.adapter = TestAdapter{ position ->

        when (position) {

            0 -> {
                val transaction = supportFragmentManager.beginTransaction()
                transaction.replace(R.id.fr_frame, OneFragment())
                transaction.disallowAddToBackStack()
                transaction.commit()
            }

            1 -> {
                val transaction = supportFragmentManager.beginTransaction()
                transaction.replace(R.id.fr_frame, TwoFragment())
                transaction.disallowAddToBackStack()
                transaction.commit()
            }

           2 -> {
                val transaction = supportFragmentManager.beginTransaction()
                transaction.replace(R.id.fr_frame, ThreerFragment())
                transaction.disallowAddToBackStack()
                transaction.commit()
            }

      }

I created the grid of the items using the RecyclerView. When a user clicks the item, the full screen fragment opens. It works well. But I see the weird situation when a user clicks on any full screen fragment surface the new fragment from the RecyclerView grid opens. It turns out that the user, as it were, clicks on the button under the fragment. How can this be avoided?

Here is a chunk of the code how the click listening is organized:

SetGrid.adapter = TestAdapter{ position ->

        when (position) {

            0 -> {
                val transaction = supportFragmentManager.beginTransaction()
                transaction.replace(R.id.fr_frame, OneFragment())
                transaction.disallowAddToBackStack()
                transaction.commit()
            }

            1 -> {
                val transaction = supportFragmentManager.beginTransaction()
                transaction.replace(R.id.fr_frame, TwoFragment())
                transaction.disallowAddToBackStack()
                transaction.commit()
            }

           2 -> {
                val transaction = supportFragmentManager.beginTransaction()
                transaction.replace(R.id.fr_frame, ThreerFragment())
                transaction.disallowAddToBackStack()
                transaction.commit()
            }

      }

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

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

发布评论

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

评论(1

檐上三寸雪 2025-02-09 11:40:24

从您所说的背景中的片段中,您的片段触发了接触式导航。您可以从后排堆栈中将其删除,因为我看到您使用了disallaDdTtoBackStack()。我怀疑它无法按预期工作,因此在片段的odCreate方法中更好地使用“ popbackstack()”。

From what you said your fragment in the background is triggering the on-touch navigations. You can remove it from the back stack as I see you used disallowAddToBackStack(). I suspect it is not working as intended so its better to "popBackStack() " in the oncreate method of the fragment.

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