当我在Kotlin中相应地单击片段A中的不同视图时,如何更改片段B上的文本视图?

发布于 2025-02-04 05:41:24 字数 295 浏览 4 评论 0原文

例如

​ 在FragmentB中,我有一个文本视图,

我想做的是,当我单击Fragmenta中的任何imageButton时,我想将特定的文本分配给FragmentB中的TextView。

例如: -

如果我单击fragmenta中的图像按钮1 1,则FragmentB中的文本应为“ Hello Jane”,

如果我单击Fragmenta中的图像按钮2,则FragmentB中的文本应为“ Hello Foster”,

等等。 ..

如何在Kotlin中做到这一点。 请帮我。

I have Two Fragments, for example - FragmentA and FragmentB

In FragmentA I have multiple ImageButtons,
In FragmentB I have a TextView

What I want to do is, when I click on any ImageButton in FragmentA then I want to assign a particular text to TextView in FragmentB.

For Example:-

If I click on Image Button 1 in the FragmentA then the text in FragmentB should be "Hello Jane"

If I click on Image Button 2 in the FragmentA then the text in FragmentB should be "Hello Foster"

and so on...

How to do this in Kotlin.
Please Help me.

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

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

发布评论

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

评论(1

动次打次papapa 2025-02-11 05:41:24

每当您需要相应地更新捆绑包并将其更新为最新单击时,就可以单击这些视图时,如何实现这一目标。当您导航到第二片片段时,您将获得最新的捆绑包.putextra()。使用相同的键将更新该值。因此,您将获得所需的文本并将其设置为Textfield。
注意您不必在创建捆绑包后立即导航。您可以或Maynot选择立即或后期进行

One way of how you can achieve this is to a have a common bundle, whenever you detect the click on those views you need to update the bundle accordingly and update it to the latest click. when you navigate to the second fragment you will get the most recent bundle .putExtra().Using the same key will update the value. so you will get the needed text and set it to your textfield.
Note: you dont have to navigate immediately after creating the bundle. You may or maynot opt to do it immediately or at a latter time.

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