Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何将新行动态附加到多行textview_Java_C#_Android_Xamarin - Fatal编程技术网

Java 如何将新行动态附加到多行textview

Java 如何将新行动态附加到多行textview,java,c#,android,xamarin,Java,C#,Android,Xamarin,我有一个多行文本视图需要显示服务器的状态。因此,当服务器状态更改时,它应该始终添加新行。但是,当我使用mTextview.Text=string.Format(“connected\n”)或mTextview.SetText(“…”)新行不会立即显示,而是在所有进程完成时显示。有人能帮我把它改成自动显示文本视图吗?THX logTextView.Text = string.Format ("Client log:\n"); ....... logTextView.Text=string.Form

我有一个多行文本视图需要显示服务器的状态。因此,当服务器状态更改时,它应该始终添加新行。但是,当我使用
mTextview.Text=string.Format(“connected\n”)
mTextview.SetText(“…”)
新行不会立即显示,而是在所有进程完成时显示。有人能帮我把它改成自动显示文本视图吗?THX

logTextView.Text = string.Format ("Client log:\n");
.......
logTextView.Text=string.Format("Socket connected to 172.27.27.1\n");
.......
logTextView.Text = logTextView.Text+string.Format ("Start send image to server\n");
.......
你应使用:

YourTextView.setText("Connected\n");
要添加多行,请使用:

YourTextView.append("another line\n");

使用该日志进程创建一个新线程,并在某些事件发生后立即调用它

例如:

class LogProcess implements Runnable {

    private String message;

    private TextView textView;

    public LogProcess(TextView textView, String message) {
        this.textView = textView;
        this.message = message;
    }

    @Override
    public void run() {
        textView.append(message);
    }

}
然后调用它:

Thread logProcess = new Thread(new LogProcess(logTextView, message));
logProcess .start();

您提到“当所有进程完成时”,它就会显示出来,进程和logTextView是一个同步进程吗?如果您想
向TextView添加
文本,最好使用
TextView.append(“\nmy new text”)。但是,由于您希望将其用于套接字,并且套接字语句将位于线程或异步任务中,因此不能在其中使用这些“更改gui语句”。你的应用程序将崩溃。@JamieRees我是说在套接字关闭后。一切都完成了,然后文本显示出来。这绝对不是我想要的。我使用了
textview.append(“abc”)
,但仍然是一样的……您是否意外地为多行textview设置了最大行数?否,我设置了
android:singleLine=“false”