Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing text from another activity

How to dynamically change the content of a TextView from another part of the screen?

I have a TabActivity class that draws a RelativeLayout that contains a TextView followed by a with several tabs. Within each tab is a separate Intent. From one of the tab intents, I would like to change the text (via .setText) of the TextView from the parent TabActvity.

Is this possible?

like image 902
ehymel Avatar asked Jul 07 '11 03:07

ehymel


1 Answers

You should use Android Architecture Components :

You can create a ViewModel containing LiveData of your data object (LiveData<String> in case you want to change only text).

When you will change your live data object from one Activity or Fragment all other Activities and Fragments observing for this live data object will get notified.

Official API doc has complete example with description.

like image 157
Vaibhav Jani Avatar answered Sep 23 '22 08:09

Vaibhav Jani