settext

Reference string resource from code

六眼飞鱼酱① 提交于 2019-11-28 12:24:17
I have the following string declared in strings.xml: <string name="last_msg">Your last click was on</string> Now when someone clicks a button, I want a textview to show this string, with a space, then a variable value that is a timestamp. Unfortunately, using @string/last_msg isn't working, and I'm not sure how to do this properly so I'm not hardcoding in content. Here's my code for the onClick function: public void showMsgNow(View view) { TextView lastMsg = (TextView)findViewById(R.id.textView2); long currentTimeStamp = System.currentTimeMillis(); lastMsg.setText(@string/last_msg + " " +

android-TextView setText in Html.fromHtml to display image and text [duplicate]

五迷三道 提交于 2019-11-28 06:37:40
This question already has an answer here: Html.ImageGetter TextView 3 answers I try to display the text and image in Html.fromHtml() but it is doesn't work in image display. message = (TextView) findViewById (R.id.message); message.setText(Html.fromHtml( "<p><b>First, </b><br/>" + "Please press the" + "<img src = 'addbutton.png' />" + " to insert a new event.</p>")); The text are display well but the image cannot display. How can improve it? user2274349 This is the coding for reference to user pskink ... package com.tutorial.myjob; import android.app.Activity; import android.graphics.drawable

label.setText NullPointerException

[亡魂溺海] 提交于 2019-11-28 01:33:17
问题 Hi first time here but here goes: I have a JavaFX application that changes the FXML UI labels dynamically and the data is pulled from a Player class. The two classes in question are Player.java and InterfaceHandler.java . The player class stores player details and I want to pass the details to the Interface class which sets the text on the labels. As a test my FXML UI just has a button and two labels. If it click the button it calls the handleButton method it sets locationLabel to "Town" fine

Android application stops after setText on TextView

*爱你&永不变心* 提交于 2019-11-27 16:29:33
I have an android program which sends to another activity after clicking on a button. Mainly, I want to set the text from textview in the new windows so that it corresponds to the selected button. For example, if I click on button Writers, the next new activity should have a textview on which the word Writers appears. Everything works fine, except when I try to setText on the TextView icon for category. I also tried to call this change in the first activity, before launching the second one, it didn't work. I also mention that if I comment the line with the setText, the program works just fine.

Changing text from another activity

吃可爱长大的小学妹 提交于 2019-11-27 14:24:45
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? 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

Reference string resource from code

寵の児 提交于 2019-11-27 07:03:56
问题 I have the following string declared in strings.xml: <string name="last_msg">Your last click was on</string> Now when someone clicks a button, I want a textview to show this string, with a space, then a variable value that is a timestamp. Unfortunately, using @string/last_msg isn't working, and I'm not sure how to do this properly so I'm not hardcoding in content. Here's my code for the onClick function: public void showMsgNow(View view) { TextView lastMsg = (TextView)findViewById(R.id

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

北战南征 提交于 2019-11-27 06:35:10
This question already has an answer here: How to round a number to n decimal places in Java 29 answers 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.234966145 And i would want just Value of a: 5.23 Without changing the real value of a so it shows the approximate number but works

android-TextView setText in Html.fromHtml to display image and text [duplicate]

走远了吗. 提交于 2019-11-27 01:29:58
问题 This question already has an answer here: Html.ImageGetter TextView 4 answers I try to display the text and image in Html.fromHtml() but it is doesn't work in image display. message = (TextView) findViewById (R.id.message); message.setText(Html.fromHtml( "<p><b>First, </b><br/>" + "Please press the" + "<img src = 'addbutton.png' />" + " to insert a new event.</p>")); The text are display well but the image cannot display. How can improve it? 回答1: This is the coding for reference to user

Android application stops after setText on TextView

耗尽温柔 提交于 2019-11-26 18:41:09
问题 I have an android program which sends to another activity after clicking on a button. Mainly, I want to set the text from textview in the new windows so that it corresponds to the selected button. For example, if I click on button Writers, the next new activity should have a textview on which the word Writers appears. Everything works fine, except when I try to setText on the TextView icon for category. I also tried to call this change in the first activity, before launching the second one,

Android setting with TextView for Hebrew text?

点点圈 提交于 2019-11-26 17:53:26
I am setting text in TextView from string resource. Normally, Hebrew works in Right-To-Left format. When I set a text, it sets the text Right-To-Left format in LG, Samsung, Sony Phone but in HTC it does not work. It works in Left-To-Right format in HTC. Even I set Gravity to the TextView in Java file. Text in TextView should be span according to the screen size. For example if it is 320 x 480 then it display in 4 lines but if it is Galaxy Tab then there may be 2 lines. Here is my Code snippet: In Java: private TextView mVersionInfo, mVersionDescriptionOne, mVersionDescriptionTwo,