为什么我无法打印转义序列中editext在Android的? [英] Why am i not able to print escape sequence in editext in Android?
问题描述
我使用包含其中含有一些这样的转义序列为\\ n HTTP POST请求,使用\\ t等获得来自API的响应当我尝试在EDITTEXT来显示它显示为\\ n和\\ t,但我期待一个新行或水平选项卡。这是我的code:
I am getting a response from an API using HTTP POST request which contains which contains some escape sequences such as \n, \t etc. When i try to display it in editText it is displayed as \n and \t but i expect a new line or horizontal tab. This is my code :
String out1 = sys.getString("stdout");
Toast.makeText(getApplicationContext(), out1, Toast.LENGTH_LONG).show();
String time1 = sys.getString("time");
if(compile.length()>0 && time1.equalsIgnoreCase("null")){
et.setText("Compilation error "+"\n"+compile);
}
else if(compile.length()>0){
et.setText("Runtime error "+"\n"+compile);
}
else
et.setText(message.substring(2,message.length()-2)+" time: "+time1.substring(1,Math.min(time1.length(),4))+" memory: "+mem.substring(1,mem.length()-1)+"\n"+out1.substring(2,out1.length()-2));
//et.setText(result);
} catch(Exception e){
e.printStackTrace();
}
JSON对象stdout是像标准输出:5 \\ N6],并在打印的EditText它会显示5 \\ N6但我希望新的一行。有什么办法来处理所有转义序列,以便正确地显示结果。我一直在尝试这种相当长一段时间,但无法找到一个解决方案。请指导我。在此先感谢!
The JSON object stdout is something like "stdout":["5\n6"] and on printing it in editText it displays 5\n6 but i expect a new line. Is there any way to handle all escape sequences so as to properly display the result. I have been trying this for quite a while but cannot find a solution. Please guide me. Thanks in advance !!
推荐答案
首先,设置你的 EDITTEXT 在这样的xml文件:
First, set your editText in xml file like this:
<EditText
android:id="@+id/editText"
.
.
.
.
android:inputType="textMultiLine" >
现在把你的文本新行字符 -
now put your text with new line character -
et.setText("Compilation error \n compile");
这工作,享受!
这篇关于为什么我无法打印转义序列中editext在Android的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!