1.解析网站并显示
因为要处理网页读取,需要开启线程,并在UI上更新,则要使用handler
注意Handler导入的是os包
下面是MainActivity
private WebView webView;
private WebView webView;
private Handler handler=new Handler();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_http_url_connection);
webView=(WebView)findViewById(R.id.webview);
new HttpThread("http://www.baidu.com",handler,webView).start();
}
子线程类
public class HttpThread extends Thread {
private String url=null;
private Handler handler;
private WebView webView;
StringBuffer sb;
public HttpThread(String url,Handler handler,WebView webView){
this.url=url;
this.handler=handler;
this.webView&#