将文本附加到 TextView 数据类型 [英] Append text to a TextView datatype

查看:28
本文介绍了将文本附加到 TextView 数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一名初学者 android/java 程序员,我的背景主要是 C++ 和 C#.在 C# 中,如果我有一个名为 myWord 的字符串变量并且它的值为Hello",我可以使用 + 运算符附加其他信息.

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.

我在 java 中尝试了几次这个方法,显然我不能使用这个 tatic,因为 TextView 数据类型是空的.Android studio 给了我以下错误:操作符 '+' 不能应用于 'void', 'java.lang.String'

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");

我想找到一种方法将附加文本附加到Hello"的原始值,以便 displayTextView 的值将是Hello Bob!"

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!"

有什么想法吗?

我目前使用大写的S",我的应用程序可以成功访问和检索我班级的信息.每当我尝试将文本附加到 TextView 数据类型时,应用程序就会 FC.

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.

感谢大家的反馈.

推荐答案

您可以在 TextView 对象上调用 append().

You can call append() on a TextView object.

在你的情况下是:displayTextView.append("Bob!");

这篇关于将文本附加到 TextView 数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆