简体   繁体   English

如何动态地向多行文本视图中添加新行

[英]How to dynamically add a new line to a multiline textview

I have a multiline textview need to show the status of the server. 我有一个多行textview需要显示服务器的状态。 So it should always add a new line when server status changes. 因此,当服务器状态更改时,它应始终添加新行。 However, the new line doesn't show up immediatelly but all show up at the end. 但是,新行不会立即显示,而是全部显示在末尾。 I have set the android:singleLine="false" . 我已经设置了android:singleLine="false" I use following code to refresh the textview, but it still doesn't work. 我使用以下代码刷新textview,但仍然无法正常工作。

private void SetLogTextView (string msg)
{   
  RunOnUiThread (() => logTextView.Text=logTextView.Text+msg );
}

I have contained "\\n" in msg already. 我已经在味精中包含“ \\ n”。 I just have msg1, msg2, and msg3, I want to them to show up in sequence. 我只有msg1,msg2和msg3,我希望它们按顺序显示。 For instance, first msg1 show, then do something, then msg2 show, then do something, then msg3 show. 例如,首先显示msg1,然后执行某些操作,然后显示msg2,然后执行某些操作,然后显示msg3。 Between each there should be a time interval. 在每个之间应该有一个时间间隔。 However, they didn't show at the right time, but all pop up at the end. 但是,它们没有在正确的时间显示,而是全部在最后弹出。 This is what I want to fix. 这是我要修复的问题。 THX! 谢谢!

You can do this in below way - 您可以通过以下方式执行此操作-

private void SetLogTextView (string msg){   
    MyTextView.setText(MyTextView.getText().toString()+"\n"+msg);
}

It will add message in your text view in a new line. 它将在文本视图的新行中添加消息。

Hope it will help you. 希望对您有帮助。

Alternatively you can use StringBuilder class. 或者,您可以使用StringBuilder类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM