我希望能够获取网页的源代码(例如http://www.google.com)并将其显示在Android主要活动的文本框或标签框中......这是当前的代码我写的。但它并没有在 EditText
中加载代码public class MainActivity extends ActionBarActivity {
public String html = "";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet("http://www.google.com");
HttpResponse response = client.execute(request);
InputStream in = response.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuilder str = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
str.append(line);
}
in.close();
html = str.toString();
}
catch(Exception e){}
EditText t = (EditText)findViewById(R.id.editText);
t.setText(html);
}
答案 0 :(得分:0)
我认为EditText
应该与TextView
相关联。在布局文件中进行类似于此example的更改。您将获得显示的内容。我希望它有所帮助。试试看。如果它不起作用,请告诉我。我相信它会奏效。
使用t.setText(html, TextView.BufferType.EDITABLE)
;