我使用 putExtras 和 getExtras 从一个 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/