Java 如何正确更新textView?

Java 如何正确更新textView?,java,android,xml,Java,Android,Xml,你好,我正在学习一本关于学习Android的书籍教程,但是这本书已经过时了。我得到一个“字符串文字无法翻译”和“不要将文本与setText连接”。我想知道更新TextView的正确方法是什么?我想这就是我想要做的 <TextView android:id="@+id/textScore" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text=

你好,我正在学习一本关于学习Android的书籍教程,但是这本书已经过时了。我得到一个“字符串文字无法翻译”和“不要将文本与setText连接”。我想知道更新TextView的正确方法是什么?我想这就是我想要做的

<TextView
    android:id="@+id/textScore"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Score: 999"
    android:textSize="36sp"
    android:layout_alignParentBottom="true"
    android:layout_toLeftOf="@+id/textOperator"
    android:layout_toStartOf="@+id/textOperator" />

<TextView
    android:id="@+id/textLevel"`enter code here`
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Level: 4"
    android:textSize="36sp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:layout_marginRight="11dp"
    android:layout_marginEnd="11dp" />
遵循指导原则()。例如,指定与分数相关的字符串,如下所示:

<string name="score">Score: %1$d</string>
Resources res = getResources();
String text = res.getString(R.string.score, currentScore);
textObjectScore.setText(text);
通过这种方式,您可以安全地翻译字符串、提供复数和格式。

遵循指导原则()。例如,指定与分数相关的字符串,如下所示:

<string name="score">Score: %1$d</string>
Resources res = getResources();
String text = res.getString(R.string.score, currentScore);
textObjectScore.setText(text);

通过这种方式,您可以翻译字符串、提供复数和安全的格式。

这两者都与翻译有关

“无法翻译字符串文字”。这是一个警告,告诉您无论用户将手机更改为何种语言,此字符串都将使用英语。对于专业应用程序,您可以在strings.xml中定义字符串,并在应用程序中使用该字符串。这允许为手机的区域设置选择字符串,假设您提供了翻译文件

“不要将文本与setText连接”。用你的母语做这件事没有实际问题。问题是在其他语言中,你所做的可能没有语法意义。相反,您应该在strings.xml中定义一个带有输入变量的字符串,并使用getString来填充这些变量


但是,如果你能很快地把一些不适合国际发行的东西拼凑在一起,你就可以了。

这两个都与翻译有关

“无法翻译字符串文字”。这是一个警告,告诉您无论用户将手机更改为何种语言,此字符串都将使用英语。对于专业应用程序,您可以在strings.xml中定义字符串,并在应用程序中使用该字符串。这允许为手机的区域设置选择字符串,假设您提供了翻译文件

“不要将文本与setText连接”。用你的母语做这件事没有实际问题。问题是在其他语言中,你所做的可能没有语法意义。相反,您应该在strings.xml中定义一个带有输入变量的字符串,并使用getString来填充这些变量


但是,如果你能快速地将一些不适合国际发行的东西组合在一起,你就可以了。

如果你创建一个
String textToSet=“Score:”+currentScore
then
textObjectScore.setText(textToSet)?如果创建
字符串textToSet=“Score:+currentScore
then
textObjectScore.setText(textToSet)