XmlAdapters中的ProgressDialog示例错误(ProgressDialog in XmlAdapters sample error)

编程入门 行业动态 更新时间:2024-10-24 22:24:11
XmlAdapters中的ProgressDialog示例错误(ProgressDialog in XmlAdapters sample error)

以下是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

更多推荐

本文发布于:2023-08-05 04:03:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1428016.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:示例   错误   ProgressDialog   XmlAdapters   sample

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!