[英]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.