try {
doc = Jsoup.parse(new URL("http://www.51yam.com"), 5000);
} catch (MalformedURLException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
final List<Map<String, String>> list = new ArrayList<Map<String, String>>();
Elements es = doc.getElementsByClass("subnav");
for (int i=0;i<es.size();i++) {
Element e = es.get(i);
int count = e.getElementsByTag("a").size();
for(int j=0;j<count;j++)
{
Map<String, String> map = new HashMap<String, String>();
Element ex = e.getElementsByTag("a").get(j);
map.put("title", ex.text());
map.put("href", "http://www.51yam.com/"+ex.attr("href"));
list.add(map);
}
}
ListView listView = (ListView) findViewById(R.id.listView1);
listView.setAdapter(new SimpleAdapter(this, list, android.R.layout.simple_list_item_2,
new String[] { "title","href" }, new int[] {
android.R.id.text1,android.R.id.text2
}));
listView.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View v, int position,long id) {
//Toast.makeText(getApplicationContext(), (TextView), duration)
System.out.println("position:"+position);
System.out.println("id:"+id);
//Toast.makeText(_GetWebResoureActivity.this, list.get(position).get("href"), Toast.LENGTH_SHORT).show();
Intent intent = new Intent(v.getContext(),topicdetails.class);
intent.putExtra("src", list.get(position).get("href"));
startActivityForResult(intent,0);
}
});
package com.android.web;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.EditText;
import java.lang.Object;
public class topicdetails extends Activity {
private EditText editText;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.topiccontent);
editText = (EditText)this.findViewById(R.id.editText);
String srcUrl = getIntent().getStringExtra("src");
editText.setText(srcUrl);
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.web"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="7" />
<!-- 加入访问网络的权限 -->
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name="._GetWebResoureActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".topicdetails"></activity>
</application>
</manifest>
package com.android.web;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.lang.Object;
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.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;
public class _GetWebResoureActivity extends Activity {
Document doc;
@Override
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("http://www.51yam.com"), 5000);
} catch (MalformedURLException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
final List<Map<String, String>> list = new ArrayList<Map<String, String>>();
Elements es = doc.getElementsByClass("subnav");
for (int i=0;i<es.size();i++) {
Element e = es.get(i);
int count = e.getElementsByTag("a").size();
for(int j=0;j<count;j++)
{
Map<String, String> map = new HashMap<String, String>();
Element ex = e.getElementsByTag("a").get(j);
map.put("title", ex.text());
map.put("href", "http://www.51yam.com/"+ex.attr("href"));
list.add(map);
}
}
ListView listView = (ListView) findViewById(R.id.listView1);
listView.setAdapter(new SimpleAdapter(this, list, android.R.layout.simple_list_item_2,
new String[] { "title","href" }, new int[] {
android.R.id.text1,android.R.id.text2
}));
listView.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View v, int position,long id) {
//Toast.makeText(getApplicationContext(), (TextView), duration)
System.out.println("position:"+position);
System.out.println("id:"+id);
//Toast.makeText(_GetWebResoureActivity.this, list.get(position).get("href"), Toast.LENGTH_SHORT).show();
Intent intent = new Intent(v.getContext(),topicdetails.class);
intent.putExtra("src", list.get(position).get("href"));
startActivityForResult(intent,0);
}
});
}
/**
* @param urlString
* @return
*/
public String getHtmlString(String urlString) {
try {
URL url = null;
url = new URL(urlString);
URLConnection ucon = null;
ucon = url.openConnection();
InputStream instr = null;
instr = ucon.getInputStream();
BufferedInputStream bis = new BufferedInputStream(instr);
ByteArrayBuffer baf = new ByteArrayBuffer(500);
int current = 0;
while ((current = bis.read()) != -1) {
baf.append((byte) current);
}
return EncodingUtils.getString(baf.toByteArray(), "gbk");
} catch (Exception e) {
return "";
}
}
}
package com.android.web;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.EditText;
import java.lang.Object;
public class topicdetails extends Activity {
private EditText editText;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.topiccontent);
editText = (EditText)this.findViewById(R.id.editText);
String srcUrl = getIntent().getStringExtra("src");
editText.setText(srcUrl);
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有