[英]How to make a TextView multiline programmatically in Android (Java)
[英]How to refresh the text in a multiline textview in android
我在android客户端上有一个textview来显示服务器的状态。 状态信息将附加为
logTextView = FindViewById (Resource.Id.LOGtextView);
logTextView.SetText ("Client log:\n", TextView.BufferType.Normal);
logTextView.Append(string.Format("Socket connected to 172.27.27.1\n"));
logTextView.Append(string.Format ("Start send image to server\n"));
logTextView.Append(string.Format ("Successfully send the image to server\n"));
logTextView.Append(string.Format ("Successfully receive the image from server\n"));
因此,当服务器状态更改时,它应始终添加新行。 但是,新行不会立即显示,而是在流程结束时全部弹出。 我已经设置了android:singleLine="false"
。
您可以使用计时器动态更新textview。
private Timer timer = new Timer();
private TimerTask timerTask;
timerTask = new TimerTask() {
@Override
public void run() {
//refresh your textview
}
};
timer.schedule(timerTask, 0, 10000);
通过timer.cancel()取消它。 在您的run()方法中,您可以使用runOnUiThread();。
无需将字符串附加到文本视图,而是将状态附加到字符串并将其设置为文本到textView。
logTextView = FindViewById (Resource.Id.LOGtextView);
String status = string.Format("Client log:\n");
logTextView.SetText(status);
// Server status updated
status.concat(string.Format("Socket connected to 172.27.27.1\n"))
logTextView.SetText(status);
// so on
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.