我想在动态创建的列表视图中执行异步任务,但它给了我错误
这是我的代码
public class TenderViewActivity extends ListActivity {
ArrayList<Spanned> tenders;
@SuppressWarnings("unchecked")
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
Downloaditems dw_tender=new Downloaditems();
dw_tender.execute();
}//onCreate
@SuppressWarnings("unused")
private class Downloaditems extends AsyncTask<ArrayList<Spanned>, ArrayList<Spanned>, ArrayList<Spanned>> {
@Override
protected ArrayList<Spanned> doInBackground(ArrayList<Spanned>... params) {
Intent intent = getIntent();
cat = intent.getStringExtra(BidActivity.EXTRA_MESSAGE4);
tender_name = intent.getStringExtra(BidActivity.EXTRA_MESSAGE3);
title=intent.getStringExtra(BidActivity.EXTRA_MESSAGE5);
setTitle(title);
ArrayList<Spanned> tender_res=tenderlist(cat,tender_name);
return tender_res;
}
protected void onPostExecute(ArrayList<Spanned> result) {
setListAdapter(new ArrayAdapter<Spanned>this,R.layout.tender_listing,R.id.basic_details,tenders));
tenders=result;
}
}
这行 setListAdapter(新的ArrayAdapterthis,R.layout.tender_listing,R.id.basic_details,招标)); 在onpostexecute方法中给出了我的错误
构造函数ArrayAdapter(TenderViewActivity.Downloaditems,int,int,ArrayList)未定义
请帮助..
答案 0 :(得分:2)
更改
setListAdapter(new ArrayAdapter<Spanned>(this,R.layout.tender_listing,R.id.basic_details,tenders));
到
setListAdapter(new ArrayAdapter<Spanned>(TenderViewActivity.this,R.layout.tender_listing,R.id.basic_details,result));
在您的情况下,this
不会引用活动背景。
而不是tenders
使用result
作为最后一个参数。还要添加@Override注释
@Override
protected void onPostExecute(ArrayList<Spanned> result) {
super.onPostExecute(result);
答案 1 :(得分:1)
at
setListAdapter(new ArrayAdapter<Spanned>this,R.layout.tender_listing,R.id.basic_details,tenders));
而不是使用TenderViewActivity.this