gpt4 book ai didi

java - 回显 TextView 的内容?

转载 作者:行者123 更新时间:2023-11-30 03:21:27 33 4
gpt4 key购买 nike

我有一节课用这段代码

public boolean busybox() throws IOException
{

try
{

Process p =Runtime.getRuntime().exec("busybox");
InputStream a = p.getInputStream();
InputStreamReader read = new InputStreamReader(a);
BufferedReader in = new BufferedReader(read);
StringBuilder buffer = new StringBuilder();

String line = null;

try {

while ((line = in.readLine()) != null) {
buffer.append(line);
}

} finally {
read.close();
in.close();
}

String result = buffer.toString().substring(0, 15);
System.out.println(result);

return true;
} catch (Exception e) {
e.printStackTrace();
}

return false;
}

在另一个类中我有这段代码

try {
if(root.busybox()) {

Busybox.setText(Html.fromHtml((getString(R.string.busybox))));


}
else {

Busybox.setText(Html.fromHtml((getString(R.string.no))));

}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});

如果我想在这个 TextView 中写入由 System.out.println(result) 生成的输出;

我该怎么办?提前致谢!我做了几次尝试,但我有几个错误,代码是错误的。

最佳答案

public boolean busybox() 的返回类型更改为字符串,如 public String busybox()return result

然后使用

try {
String myResult=root.busybox();
if(myResult!=null&&myResult.length>0) {

Busybox.setText(Html.fromHtml((myResult)));


}
else {

Busybox.setText(Html.fromHtml((getString(R.string.no))));

}
}

关于java - 回显 TextView 的内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19063964/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com