ProgressDialog似乎为时已晚,自败得太快 [英] ProgressDialog appears too late and dissapears too fast

查看:1736
本文介绍了ProgressDialog似乎为时已晚,自败得太快的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然我更新我的数据库我想显示一个进度对话框。我的问题是,ProgressDialog越来越晚出现,4-5秒后,再出现和消失速度非常快,它在屏幕上停留几毫秒,几乎无法看到它,那么新的数据会立即显示在列表中。这使我觉得ProgressDialog正在等待数据库进行更新(它不会花费太多,大概4,5秒),然后它显示在屏幕上,但被驳回非常快。我想ProgressDialog立即出现我preSS的更新按钮,并在屏幕上停留约4-5秒。

While I'm updating my database I want to display a progress dialog. My problem is that the ProgressDialog is getting late to appear,after 4-5 seconds, then appears and disappears very fast, it stays on screen few milliseconds almost you can't see it, then new data are shown in the list immediately. This makes me think that the ProgressDialog is waiting for database to be updated(it doesn't take much, about 4,5 seconds) and then it shows on the screen but is dismissing very fast. I would like the ProgressDialog appear immediately I press the 'Update' button and stay on the screen about 4-5 seconds.

class MyAsyncTask extends AsyncTask<Void, Void, Void>{

        ProgressDialog myprogsdial;
        @Override
        protected void onPreExecute(){
            myprogsdial = ProgressDialog.show(MyActivity.this, null, "Upgrade", true);
        }

        @Override
        protected Void doInBackground(Void... params) {
            // TODO Auto-generated method stub

                runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        // TODO Auto-generated method stub

                        RefreshDataBase();

                    }
                });

            return null;
        }

        @Override
        protected void onPostExecute(Void result){
            myprogsdial.dismiss();
        }

    }

当我称之为新MyAsyncTask()执行();

推荐答案

我已经解决了它,使用的这个答案弗拉基米尔·伊万诺夫的。
我已经由外观隔开的功能。
我在 doInBackground保持功能(下载新数据)() onPostExecute()我更新列表:拿到新的适配器,名为 setListAdaper() notifyDataSetChanged
当然,我退出使用 runOnUiThread()。感谢所有的提示。

I have solved it, using this answer of Vladimir Ivanov. I have separated the functionality by the appearance. I have kept the functionality(downloading new data) in doInBackground() and in onPostExecute() I updated the list: get the new adapter,called setListAdaper() and notifyDataSetChanged. Of course, I quit using runOnUiThread(). Thanks to all for hints.

这篇关于ProgressDialog似乎为时已晚,自败得太快的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆