0

I want to put a ProgressDialog on my program while calculating something.I tried many things but any of them helps me.Here is my code ;

                dialog=ProgressDialog.show(this, "calculating", "Please wait while the calculation is getting done.",true);

                this.runOnUiThread(new Runnable() {

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

                changeHelp = 0;

                if(screenNumber == 1){
                    compareImages(3.3, 0.12);
                }

                else if(screenNumber==2 || screenNumber == 4){
                    compareImages(1.4, 0.1);
                }
                else if ( screenNumber == 3)
                    compareImages(0.41, 0.1);
                else
                    compareImages(3.3, 0.0676);

                dialog.dismiss();

                screenNumber++; }
        });

There are a lot of question in there about this problem.Although ı tried many of them,ı couldn't deal with the problem.I don't want to use asynctask.Pls help me .

----EDİT----

I have added thread.sleep(2000) in try but it is still not working.I think that ı am doing something wrong in while putting dialog.dismiss but ı couldn't find where the problem is?

4

1 回答 1

0

我认为你ProgressDialog的展示时间很短,因为你没有做至少持续一秒钟但更短的任务。

如果你想实现你的目标,更好的方法是使用AsyncTask,是的,你不想使用它,但为了你的目标,我认为 AsyncTask 是你可以使用的最佳方法。

但作为解决方案,有一种方法Thread.sleep()可以模拟一些“将持续”更长时间的任务。但是您需要从后台线程调用(以避免 UI 冻结)。对话的推进是可以从任何类型的线程中解散的。

于 2013-09-15T12:35:10.677 回答