【发布时间】:2011-10-20 21:44:15
【问题描述】:
我用 JSoup 解析了几个项目,我想将它们添加到列表视图中,最好通过这样的数组列表:
End date: 08-10-2012
Left: € 38,50
谁能帮帮我? 提前谢谢你。
JSoup 的结果为 System.out.println:
End date: // td:eq(0)
Left: // td:eq(0)
08-10-2012 // td:eq(1)
€ 38,50 // td:eq(1)
我的代码:
@Override
protected void onPostExecute(String result) {
//publishProgress(false);
TextView tv = (TextView)findViewById(R.id.lbl_top);
ListView kp = (ListView)findViewById(R.id.kpn);
tv.setText("");
Document doc = Jsoup.parse(kpn);
Elements tdsFromSecondColumn = doc.select("table.personaltable td:eq(0)");
Elements tdsFromSecondColumn1 = doc.select("table.personaltable td:eq(1)");
for (Element tdFromSecondColumn : tdsFromSecondColumn) {
System.out.println(tdFromSecondColumn.text());
tv.setText(tdFromSecondColumn.text());
//kp.setAdapter(adapter);
}
for (Element tdFromSecondColumn1 : tdsFromSecondColumn1) {
System.out.println(tdFromSecondColumn1.text());
}
编辑:
@Override
protected void onPostExecute(String result) {
//publishProgress(false);
// create the grid item mapping
ListView kp = (ListView)findViewById(R.id.kpn);
String[] from = new String[] {"col_1", "col_2"};
int[] to = new int[] { R.id.lbl_password, R.id.lbl_result };
List<HashMap<String, String>> fillMaps = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map = new HashMap<String, String>();
TextView tv = (TextView)findViewById(R.id.lbl_top);
tv.setText("");
Document doc = Jsoup.parse(kpn);
Elements tdsFromSecondColumn = doc.select("table.personaltable td:eq(0)");
Elements tdsFromSecondColumn1 = doc.select("table.personaltable td:eq(1)");
for (Element tdFromSecondColumn : tdsFromSecondColumn) {
map.put("col_1", tdFromSecondColumn.text());
fillMaps.add(map);
System.out.println(tdFromSecondColumn.text());
tv.setText(tdFromSecondColumn.text());
//kp.setAdapter(adapter);
}
for (Element tdFromSecondColumn1 : tdsFromSecondColumn1) {
map.put("col_2", tdFromSecondColumn1.text());
fillMaps.add(map);
System.out.println(tdFromSecondColumn1.text());
}
SimpleAdapter adapter = new SimpleAdapter(AndroidLogin.this, fillMaps, R.layout.main, from, to);
kp.setAdapter(adapter);
应用程序崩溃,Logcat:
ERROR/AndroidRuntime(9105): java.lang.IllegalArgumentException: Object must not be null
【问题讨论】:
标签: android listview arraylist