android - 在新行中在 TextView 中传递一个新字符串

标签 android string textview

我使用 putExtrasgetExtras 从一个 Activity 发送一个字符串到另一个 Activity。 然后我将这个字符串显示到 TextView。当我返回并选择另一个字符串时,它会覆盖 TextView 中的前一个字符串。 我想将新字符串放在 textView 的新行中。 这个怎么做? (我用一个按钮发送字符串) 这是我在接收 Activity 中的代码:

   @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_completed_tasks);


    TextView completedTasksView = (TextView)findViewById(R.id.completed_tasks);


    Intent intent = getIntent();

    String completedTasks = intent.getExtras().getString("completedTasks");
    completedTasksView.setText(completedTasks);


}

}

最佳答案

根据:TextView

append(CharSequence text)

Convenience method: Append the specified text to the TextView's display buffer, upgrading it to BufferType.EDITABLE if it was not already editable.

所以使用:

completedTasksView.append("\n" + completedTasks);

关于android - 在新行中在 TextView 中传递一个新字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38077575/

相关文章:

android - TextView 在屏幕上显示很小

java - api低于26的设备如何使用base 64?

android - Httpclient 替代方案

android - 创建两个 APK 的两个启动器 Activity

c - For 循环不会在 strlen 上停止

python - 如何使用正则表达式提取 Pandas 数据框中的特定内容?

java - 改变 textView 的布局引力

java - 如何在android中将textview设置为方法输出?

python - 使用正则表达式查找所有出现的交替数字

java - android - 如何从对象设置文本