我必须在我的应用程序中加载 XML 数据,我在扩展 AsyncTask 的 Activity 类的子类中这样做:
public class MyActivity extends Activity {
ArrayList<Offre> listOffres;
private class DownloadXML extends AsyncTask<Void, Void,Void>
{
protected Void doInBackground(Void... params)
{
listOffres = ContainerData.getFeeds();
return null;
}
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_liste_offres);
DownloadXML.execute(); // Problem here !
for(Offre offre : listOffres) { // etc }
}
}
我不知道如何在这里使用 execute(),我有以下错误:
Cannot make a static reference to the non-static method execute(Integer...) from the type AsyncTask
我猜是一些参数,但是什么?
谢谢。
最佳答案
您需要创建一个DonwloadXML
文件的实例并调用该方法的execute()
:
DownloadXML task=new DownloadXML();
task.execute();
编辑:您可能还应该从 doInBackground()
返回 listOffers
并在 onPostExecute() 中处理数组
您的 AsynTask
方法。你可以看看这个简单的 AsyncTask tutorial .
关于安卓 : how to execute AsyncTask?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11451782/