以下是XmlAdapters示例代码。 当我添加ProgressDialog如下所示接收错误'适配器类型中的方法loadCursorAdapter(Context,int,String,Object ...)不适用于参数(new AsyncTask(){},int,String)'
final ProgressDialog _progressDialog = new ProgressDialog(this); _progressDialog.setTitle("Loading ..."); _progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); new AsyncTask<Void, Void, Void>() { protected Void doInBackground(Void ... urls) { setContentView(R.layout.photos_list); setListAdapter(Adapters.loadCursorAdapter(this, R.xml.photos, "content://xmldocument/?url=" + Uri.encode("http://picasaweb.google.com/data/feed/api/featured?max-results=50&thumbsize=144c"))); } protected void onPostExecute(Void result) { _progressDialog.dismiss(); } protected void onPreExecute(Void no) { _progressDialog.show(); } }.execute();Below are the XmlAdapters sample code. When i add the ProgressDialog as show below receive an error 'The method loadCursorAdapter(Context, int, String, Object...) in the type Adapters is not applicable for the arguments (new AsyncTask(){}, int, String)'
final ProgressDialog _progressDialog = new ProgressDialog(this); _progressDialog.setTitle("Loading ..."); _progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); new AsyncTask<Void, Void, Void>() { protected Void doInBackground(Void ... urls) { setContentView(R.layout.photos_list); setListAdapter(Adapters.loadCursorAdapter(this, R.xml.photos, "content://xmldocument/?url=" + Uri.encode("http://picasaweb.google.com/data/feed/api/featured?max-results=50&thumbsize=144c"))); } protected void onPostExecute(Void result) { _progressDialog.dismiss(); } protected void onPreExecute(Void no) { _progressDialog.show(); } }.execute();最满意答案
'适配器类型中的方法loadCursorAdapter(Context,int,String,Object ...)不适用于参数(new AsyncTask(){},int,String)'
表示loadCursorAdapter将Application或Activity Context作为第一个param而不是AsyncTask,因此将代码更改为:
new AsyncTask<Void, Void, Void>() { protected Void doInBackground(Void ... urls) { setContentView(R.layout.photos_list); setListAdapter(Adapters.loadCursorAdapter(Your_Current_Activity.this, R.xml.photos, "content://xmldocument/?url=" + Uri.encode("http://picasaweb.google.com/data/feed/api/featured?max-results=50&thumbsize=144c"))); //your code here...并且我不确定这会有效,因为你试图从AsyncTask的doInBackground方法访问Ui元素,这些方法总是在后台线程中执行。
您需要在onPostExecute移动所有与Ui相关的代码,以便在后台执行完成后更新Ui
'The method loadCursorAdapter(Context, int, String, Object...) in the type Adapters is not applicable for the arguments (new AsyncTask(){}, int, String)'
means loadCursorAdapter take Application or Activity Context as first param instead of AsyncTask so change your code as :
new AsyncTask<Void, Void, Void>() { protected Void doInBackground(Void ... urls) { setContentView(R.layout.photos_list); setListAdapter(Adapters.loadCursorAdapter(Your_Current_Activity.this, R.xml.photos, "content://xmldocument/?url=" + Uri.encode("http://picasaweb.google.com/data/feed/api/featured?max-results=50&thumbsize=144c"))); //your code here...and i'm not sure this will work becuase you are trying to accessing Ui elements from doInBackground method of AsyncTask whcih always exectue in Background Thread.
you will need to move all Ui related code in onPostExecute to update Ui after background execution complete
更多推荐
发布评论