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 appen
You can call append()
on a TextView object.
In your case it would be: displayTextView.append("Bob!");
First letter of String is not small letter. To take a String variable in java you have to write String var;
So, for android use following code:
TextView displayTextView = null;
TextView displayTextView = (TextView) findViewById(R.id.myText);
String myWord = "Your";
displayTextView.setText("Hello " + myword);
This should work.
Why nobody suggested getText()
method ?
TextView displayTextView = null;
displayTextView.setText("text1");
displayTextView.setText(displayTextView.getText() + "text2");//poor and weak
or better for longer strings:
SpannableString ss =new SpannableString();
ss.append("text1").append("text2");
displayTextView.setText(ss);
If you are using TextView, use append. For example:
TextView textView = (TextView) findViewById(R.id.myText);
textView.setText("Hello");
textView.append(" Bob!");
Your issue is on your declaration of the String instance in both the method and the variable.
It requires a "S" not a lower case s.
Also the "+" sign does work, it is just your String declaration as pointed out.
All the best :)