ProgressDialog没有出现在活动了 [英] ProgressDialog not showing up in activity

查看:104
本文介绍了ProgressDialog没有出现在活动了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想包括ProgressDialog在我的应用程序。但它没有显示出来。

I am trying to include a ProgressDialog in my application. But it is not showing up.

下面就是我使用ProgressDialog的code片断:

Here's the code snippet where i use the ProgressDialog:

public class abcActivity extends Activity {
    public boolean onOptionsItemSelected(MenuItem item) {
        case XYZ:
            ProgressDialog dialog = ProgressDialog.show(abcActivity.this, "", "Please wait for few seconds...", true);
            callSomeFunction();
            dialog.dismiss();
            showToast(getString(R.string.SomeString));
            break;
    }
}

有谁知道为什么对话框不显示出来?任何线索?

Does anyone know why the dialog is not showing up? Any clues?

推荐答案

我觉得你的code是错误的,你在UI线程做的所有的感觉。你必须把callsomefunction()到后台线程。

I think your code is wrong in a sense that you do all in the UI thread. You have to put callsomefunction() into a background thread.

public void runSomething()
{
    showDialog(BACKGROUND_ID);
    Thread t = new Thread(new Runnable() 
    {                   
        public void run() 
        {
            //do something
            handler.post(finishThread);
        }
    });

    t.start();
    // The progress wheel will only show up once all code coming here has been executed
}

和以及

protected Dialog onCreateDialog(int id)
{
    if(progressDialog == null) progressDialog = new ProgressDialog(this);
    return progressDialog;
}

@Override
protected void onPrepareDialog(int id, Dialog dialog)
{
    if(id == BACKGROUND_ID) 
    {
        progressDialog.setIndeterminate(true);
        progressDialog.setCancelable(false);
        progressDialog.setMessage("running for long ...");
    }
}

Runnable finishThread = new Runnable()
{       
    public void run() 
    {
//long running
        if(progressDialog != null) progressDialog.dismiss();
    }
};

这篇关于ProgressDialog没有出现在活动了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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