Append text to a TextView datatype

后端 未结 5 1152
陌清茗
陌清茗 2021-02-05 08:39

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

相关标签:
5条回答
  • 2021-02-05 09:05

    You can call append() on a TextView object.

    In your case it would be: displayTextView.append("Bob!");

    0 讨论(0)
  • 2021-02-05 09:11

    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.

    0 讨论(0)
  • 2021-02-05 09:16

    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);
    
    0 讨论(0)
  • 2021-02-05 09:19

    If you are using TextView, use append. For example:

    TextView textView = (TextView) findViewById(R.id.myText);
    textView.setText("Hello");
    textView.append(" Bob!");
    
    0 讨论(0)
  • 2021-02-05 09:19

    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.

    Here is how it looks

    All the best :)

    0 讨论(0)
提交回复
热议问题