AsyncTask、CustomBaseAdapter 和 Listview
我有一个 CustomBaseAdapter,我用它填充某些字段:
public ArrayList<SearchResults> GetSearchResults(){
ArrayList<SearchResults> results = new ArrayList<SearchResults>();
Document doc = Jsoup.parse(kpn);
Elements tdsFromSecondColumn = doc.select("table.personaltable td:eq(0)");
Elements tdsFromSecondColumn1 = doc.select("table.personaltable td:eq(1)");
SearchResults sr1 = new SearchResults();
for (Element tdFromSecondColumn : tdsFromSecondColumn) {
sr1 = new SearchResults();
sr1.setNaam(tdFromSecondColumn.text());
results.add(sr1);
}
for (Element tdFromSecondColumn1 : tdsFromSecondColumn1) {
sr1 = new SearchResults();
sr1.setWaarde(tdFromSecondColumn1.text());
results.add(sr1);
}
return results;
}
我想在 AsyncTask 的 onPostExecute 中启动它,但我强制关闭:
@Override
protected void onPostExecute(String result) {
ListView kp = (ListView)findViewById(R.id.kpn);
ArrayList<SearchResults> searchResults = GetSearchResult();
kp.setAdapter(new MyCustomBaseAdapter(this, searchResults)); <--- think here is the error
progress.dismiss();
}
这段代码可能吗? 如果没有应该改变什么。 先感谢您。
I have a CustomBaseAdapter with which i fill certain fields:
public ArrayList<SearchResults> GetSearchResults(){
ArrayList<SearchResults> results = new ArrayList<SearchResults>();
Document doc = Jsoup.parse(kpn);
Elements tdsFromSecondColumn = doc.select("table.personaltable td:eq(0)");
Elements tdsFromSecondColumn1 = doc.select("table.personaltable td:eq(1)");
SearchResults sr1 = new SearchResults();
for (Element tdFromSecondColumn : tdsFromSecondColumn) {
sr1 = new SearchResults();
sr1.setNaam(tdFromSecondColumn.text());
results.add(sr1);
}
for (Element tdFromSecondColumn1 : tdsFromSecondColumn1) {
sr1 = new SearchResults();
sr1.setWaarde(tdFromSecondColumn1.text());
results.add(sr1);
}
return results;
}
I want to fire this up the the onPostExecute of a AsyncTask but i get a force close:
@Override
protected void onPostExecute(String result) {
ListView kp = (ListView)findViewById(R.id.kpn);
ArrayList<SearchResults> searchResults = GetSearchResult();
kp.setAdapter(new MyCustomBaseAdapter(this, searchResults)); <--- think here is the error
progress.dismiss();
}
Is this code possible?
If no what should be changed.
Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,我通过这样做摆脱了异常:
但是 JSoup 仍然错误地填充了字段,首先显示所有 naam 字段,然后显示 waarde 字段。
它应该是:
有人知道如何组合 JSoup 的 2 个 for 循环,以便正确填充字段:
这里是我的 CustomBaseAdapter 按要求:
Ok, i got rid of the exception by doing:
But the fields are still filled incorrectly with JSoup, first all the naam fields are displayed and then the waarde fields.
It should be:
Does somebody know how to combine the 2 for loops of JSoup so that the fields are filled correctly:
Here my CustomBaseAdapter as requested: