0

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.

1 Answers1

0

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.