settext

Changing text from another activity

元气小坏坏 提交于 2019-11-26 16:45:57
问题 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? 回答1: You should use Android Architecture Components : You can create a ViewModel containing LiveData of your data object (

How to print a double with two decimals in Android? [duplicate]

久未见 提交于 2019-11-26 12:04:30
问题 This question already has answers here : How to round a number to n decimal places in Java (31 answers) Closed 3 years ago . Maybe this is a silly question, but I cannot guess how to solve it if it\'s not creating a method. Maybe there\'s a \"natural way\" to do it, like in C for example. Here\'s the problem: I have a var: double a; And I want to show it only with 2 or 3 decimals. When I try to show it: Text.setText(\"Value of a: \" + String.valueOf(a)); It gives something like: Value of a: 5