文档详情

《《android解析HTML》.doc

发布:2015-10-01约3.09千字共6页下载文档
文本预览下载声明
此文档为android对HTML的解析 下面为XML代码: ?xml version=1.0 encoding=utf-8? LinearLayout xmlns:android=/apk/res/android android:layout_width=fill_parent android:layout_height=fill_parent android:orientation=vertical Button android:id=@+id/button1 android:layout_width=fill_parent android:layout_height=wrap_content android:text=加载 / ListView android:id=@+id/listView1 android:layout_width=fill_parent android:layout_height=wrap_content /ListView /LinearLayout 下面为java代码: package com.android.web; import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; import .MalformedURLException; import .URL; import .URLConnection; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.http.util.ByteArrayBuffer; import org.apache.http.util.EncodingUtils; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.jsoup.select.Elements; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.ListView; import android.widget.SimpleAdapter; public class _GetWebResoureActivity extends Activity { Document doc; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); findViewById(R.id.button1).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { load(); } }); } protected void load() { try { doc=Jsoup.parse(new URL(), 5000); } catch (MalformedURLException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } ListMapString, String list = new ArrayListMapString, String(); Elements es = doc.getElementsByClass(topic); for (Element e : es) { MapString, String map = new HashMapString, String(); map.put(title, e.getElementsByTag(a).text());
显示全部
相似文档