当我在Kotlin中相应地单击片段A中的不同视图时,如何更改片段B上的文本视图?
例如
在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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
每当您需要相应地更新捆绑包并将其更新为最新单击时,就可以单击这些视图时,如何实现这一目标。当您导航到第二片片段时,您将获得最新的捆绑包
.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.