I have a textview on the android client to show the status of the server. The status information is append to the textview as
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"));
So it should always add a new line when server status changes. However, the new lines doesn't show up immediatelly but all pop up at the end show when the processes are finished. I have set the android:singleLine="false"
.
You can update the textview dynamically by using timer.
private Timer timer = new Timer();
private TimerTask timerTask;
timerTask = new TimerTask() {
@Override
public void run() {
//refresh your textview
}
};
timer.schedule(timerTask, 0, 10000);
Cancel it via timer.cancel(). In your run() method you could use runOnUiThread();
Instead of Appending a string to the text view, append the the status to your string and set it as text to your 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.