回应TextView的内容?

时间:2013-09-28 06:13:52

标签: java android xml root busybox

我有一个使用此代码的课程

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生成的输出(结果);

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

1 个答案:

答案 0 :(得分:1)

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))));

    }
}