I'm a beginner android/java programmer and my background is primarily in C++ and C#. In C# if I have a string variable called myWord and it has a value of "Hello" I can append additional information by using the + operator.
I tried this method a few times in java and apparently I can't use this tatic because the TextView datatype is void. Android studio gives me the following error: Operator '+' cannot be applied to 'void', 'java.lang.String'
/*C # */ public string bob () { return "Bob!"; } string myWord = "Hello "; myWord = myWord + "Bob!"; //myWord is now equal to "Hello Bob!" OR myWord = "Hello " + bob(); //myWord is now equal to "Hello Bob!" */ JAVA */ TextView displayTextView = null; displayTextView.setText("Hello");
I'd like to find a way to append additional text to the original value of "Hello" so the value of displayTextView will be "Hello Bob!"
Any ideas?
Edit: I'm currently using a capital "S" and my app can successfully access and retrieve information from my class. The app would FC whenver I tried to append text to to the TextView data type.
Thank you for the feedback everyone.
In Android, the most common way to show a text is by TextView element. The whole text in the TextView is easy to make clickable implementing the onClick attribute or by setting an onClickListener to the TextView.
Just add a \n to your text. This can be done directly in your layout file, or in a string resource and will cleanly break the text in your TextView to the next line.
In android, we can set the text of TextView control either while declaring it in Layout file or by using setText() method in Activity file.
htmlToTextView. setText(HtmlCompat. fromHtml(htmlText, 0)); In the above code we are taking HTML data from fromHtml() and appending to textview using setText() .
You can call append()
on a TextView object.
In your case it would be: displayTextView.append("Bob!");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With