我试图在 TextView 中显示输出。但无法显示它。我不知道它没有显示在我的程序中 包 com.iiitb.nikhil.sindhu;
import java.io.BufferedReader;
import java.io.DataInput;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import java.util.*;
import android.util.*;
public class LinuxShellCommandAndroidProgramActivity extends Activity {
/** Called when the activity is first created. */
TextView tv;
public void onCreate(Bundle savedInstanceState) {
tv=new TextView(this);
super.onCreate(savedInstanceState);
try {
Process process = Runtime.getRuntime().exec("/system/bin/su");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
DataInputStream is=new DataInputStream(process.getInputStream());
//os = new DataOutputStream(process.getOutputStream());
os.writeBytes("/system/bin/chmod 600 /data/data/newfile\n");
os.writeBytes("cd /data/data/dalvik-cache/\n");
os.writeBytes("/system/bin/ls -l /data/dalvik-cache\n");
String output=new String();
tv.setText("hii \n");
//setContentView(tv);
String temp = new String();
while((output=is.readLine())!=null)
{
Log.i("Check ",output);
tv.append(output);
}
setContentView(tv);
os.flush();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
最佳答案
在 Textview 上设置 LayoutParameter,或者只是在您的 main.xml 文件中进行布局,然后通过 layout.addView(textview);
已编辑
在调用 superClass 之后获取 tv=new TextView(this);
像这样
super.onCreate(savedInstanceState);
tv=new TextView(this);
关于android - TextView 不显示。但是在 logcat 中显示时一切正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7454463/