Android i';我在自定义对话框中使用AsyncTask,但对话框不显示

Android i';我在自定义对话框中使用AsyncTask,但对话框不显示,android,Android,我通过create new object dot execute()调用此任务,但对话框dosnot show AsyncTask在活动中工作正常,但对话框内部不显示ProgressDialog。已尝试从对话框、显示对话框的活动、应用程序上下文中创建privid上下文。结果是一样的:我的屏幕上没有显示ProgressDialog。 有什么建议吗 class RetrieveFeedTask extends AsyncTask<String, Void, RSSFeed> {

我通过create new object dot execute()调用此任务,但对话框dosnot show AsyncTask在活动中工作正常,但对话框内部不显示ProgressDialog。已尝试从对话框、显示对话框的活动、应用程序上下文中创建privid上下文。结果是一样的:我的屏幕上没有显示ProgressDialog。 有什么建议吗

class RetrieveFeedTask extends AsyncTask<String, Void, RSSFeed> {

    private Exception exception;
    private ProgressDialog dialog;

    public RetrieveFeedTask()
    {
        dialog = new ProgressDialog(RSSReader.this);

    }

    protected RSSFeed doInBackground(String... urls) {
        try {
             URL url = new URL(urls[0]);

             // create the factory
             SAXParserFactory factory = SAXParserFactory.newInstance();
             // create a parser
             SAXParser parser = factory.newSAXParser();

             // create the reader (scanner)
             XMLReader xmlreader = parser.getXMLReader();
             // instantiate our handler
             RSSHandler theRssHandler = new RSSHandler();
             // assign our handler
             xmlreader.setContentHandler(theRssHandler);
             // get our data via the url class
             InputSource is = new InputSource(url.openStream());
             // perform the synchronous parse           
             xmlreader.parse(is);
             feed=theRssHandler.getFeed();
             // get the results - should be a fully populated RSSFeed instance, or null on error
             return feed;
        } catch (Exception e) {
            this.exception = e;
            return null;
        }
    }

    protected void onPostExecute(RSSFeed feed) {

        if (dialog.isShowing()) {
            dialog.dismiss();
        }


            TextView feedtitle = (TextView) findViewById(R.id.feedtitle);
            TextView feedpubdate = (TextView) findViewById(R.id.feedpubdate);
            ListView itemlist = (ListView) findViewById(R.id.itemlist);

            if ( feed == null)
            {
                feedtitle.setText("No RSS Feed Available");
                return;
            }

            feedtitle.setText(feed.getTitle());
            feedpubdate.setText(feed.getPubDate());
            ArrayAdapter<RSSItem> adapter = new ArrayAdapter<RSSItem>(getBaseContext(),android.R.layout.simple_list_item_1,feed.getAllItems());


            itemlist.setAdapter(adapter);

            itemlist.setOnItemClickListener(RSSReader.this);

            itemlist.setSelection(0);

        }


    }

    protected void onPreExecute() {
         this.dialog.setMessage("لحظة من فضلك");
         this.dialog.show();
    }
class RetrieveFeedTask扩展了AsyncTask{
私人例外;
私人对话;
公共检索FeedTask()
{
dialog=新建进度对话框(RSSReader.this);
}
受保护的RSSFeed doInBackground(字符串…URL){
试一试{
URL=新URL(URL[0]);
//创建工厂
SAXParserFactory=SAXParserFactory.newInstance();
//创建解析器
SAXParser parser=factory.newSAXParser();
//创建读卡器(扫描仪)
XMLReader=parser.getXMLReader();
//实例化我们的处理程序
RSSHandler-theRssHandler=新的RSSHandler();
//指派我们的处理人
setContentHandler(ThersHandler);
//通过url类获取我们的数据
InputSource is=新的InputSource(url.openStream());
//执行同步解析
parse(is);
feed=theRssHandler.getFeed();
//获取结果-应为完全填充的RSSFeed实例,或错误时为null
回馈;
}捕获(例外e){
这个异常=e;
返回null;
}
}
受保护的void onPostExecute(RSSFeed提要){
if(dialog.isShowing()){
dialog.dismise();
}
TextView feedtitle=(TextView)findViewById(R.id.feedtitle);
TextView feedpubdate=(TextView)findViewById(R.id.feedpubdate);
ListView itemlist=(ListView)findViewById(R.id.itemlist);
if(feed==null)
{
feedtitle.setText(“没有可用的RSS源”);
返回;
}
feedtitle.setText(feed.getTitle());
feedpubdate.setText(feed.getPubDate());
ArrayAdapter=newArrayAdapter(getBaseContext(),android.R.layout.simple_list_item_1,feed.getAllItems());
itemlist.setAdapter(适配器);
setOnItemClickListener(RSSReader.this);
itemlist.setSelection(0);
}
}
受保护的void onPreExecute(){
this.dialog.setMessage(“لحظةمنفضك”);
this.dialog.show();
}
AsyncTask允许正确且轻松地使用UI线程。这个班 允许在UI上执行后台操作和发布结果 线程,而无需操作线程和/或处理程序

首先,您应该调用
onPreExecute()

在执行任务之前在UI线程上调用。这一步很简单 通常用于设置任务,例如通过显示进度 用户界面中的工具栏

最后
onPostExecute()

后台计算完成后在UI线程上调用。 背景计算的结果作为结果传递到此步骤 参数

阅读有关

AsyncTask允许正确且轻松地使用UI线程。这个班 允许在UI上执行后台操作和发布结果 线程,而无需操作线程和/或处理程序

首先,您应该调用
onPreExecute()

在执行任务之前在UI线程上调用。这一步很简单 通常用于设置任务,例如通过显示进度 用户界面中的工具栏

最后
onPostExecute()

后台计算完成后在UI线程上调用。 背景计算的结果作为结果传递到此步骤 参数


阅读关于

dialog=newprogressdialog(RSSReader.this)的官方指南
oncreate section first调用或
public RetrieveFeedTask(RSSReader活动){dialog=newprogressdialog(活动);}
onPreExecute第一次调用时仍然使用相同的函数
onPostExecute
然后
onPostExecute
您确定它没有出现吗?也许太快了!,在注释行
对话框后尝试运行应用程序。dismise()
dialog=newprogressdialog(RSSReader.this)
oncreate section first调用或
public RetrieveFeedTask(RSSReader活动){dialog=newprogressdialog(活动);}
onPreExecute第一次调用时仍然使用相同的函数
onPostExecute
然后
onPostExecute
您确定它没有出现吗?也许太快了!,在注释行
对话框后尝试运行应用程序。dismise()