AsyncTask的,CustomBaseAdapter和ListView [英] AsyncTask, CustomBaseAdapter and Listview
问题描述
我有一个CustomBaseAdapter与我填补某些领域:
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;
}
我想这火一个的AsyncTask的的onPostExecute但我得到一个强制关闭:
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();
}
这是code可能吗?
如果没有什么应该被改变。
谢谢你在前进。
Is this code possible? If no what should be changed. Thank you in advance.
推荐答案
好吧,我被做掉了异常:
Ok, i got rid of the exception by doing:
kp.setAdapter(new MyCustomBaseAdapter(AppName.this, searchResults));
但字段仍与JSoup充满错误,首先是NAAM字段显示,然后waarde领域。
But the fields are still filled incorrectly with JSoup, first all the naam fields are displayed and then the waarde fields.
naam:
naam:
naam:
waarde
waarde
waarde
它应该是:
naam: waarde
naam: waarde
有人是否知道如何将2 JSoup的循环相结合,这样的字段填写正确:
Does somebody know how to combine the 2 for loops of JSoup so that the fields are filled correctly:
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);
}
下面我的要求CustomBaseAdapter:
Here my CustomBaseAdapter as requested:
public class MyCustomBaseAdapter extends BaseAdapter {
private static ArrayList<SearchResults> searchArrayList;
private LayoutInflater mInflater;
public MyCustomBaseAdapter(Context context, ArrayList<SearchResults> results) {
searchArrayList = results;
mInflater = LayoutInflater.from(context);
}
public int getCount() {
return searchArrayList.size();
}
public Object getItem(int position) {
return searchArrayList.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.test, null);
holder = new ViewHolder();
holder.txtNaam = (TextView) convertView.findViewById(R.id.naam);
holder.txtWaarde = (TextView) convertView.findViewById(R.id.waarde);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.txtNaam.setText(searchArrayList.get(position).getNaam());
holder.txtWaarde.setText(searchArrayList.get(position).getWaarde());
return convertView;
}
static class ViewHolder {
TextView txtNaam;
TextView txtWaarde;
}
}
这篇关于AsyncTask的,CustomBaseAdapter和ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!