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

查看:171
本文介绍了将文本附加到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数据类型是void。 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!);

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

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

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