我在android客户端上有一个textview来显示服务器的状态。状态信息将附加到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"
。
答案 0 :(得分:0)
您可以使用计时器动态更新文本视图。
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();
答案 1 :(得分:0)
不是将字符串附加到文本视图,而是将状态附加到字符串并将其设置为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