【问题标题】:Prevent ProgressDialog from being dismissed onClick event防止 ProgressDialog 被解除 onClick 事件
【发布时间】:2015-03-23 19:26:02
【问题描述】:

以前的帖子中已经问过这个问题,但是我尝试了很多,但似乎都没有。我有一个布尔标志,理论上应该阻止我的对话框被关闭。这是我目前所拥有的:

boolean start_match = false;    
public void WarmupDialog()
{
    if(use_warmup == true)
    {
        final ProgressDialog spinner = new ProgressDialog(this);
        spinner.setTitle("Warmup");
        spinner.setCancelable(false);
        spinner.setCanceledOnTouchOutside(false);
        timer = new CountDownTimer(300000, 1000)//5 minutes
        {
            @Override
            public void onFinish() 
            {
                spinner.cancel();
            }

            @Override
            public void onTick(long l) 
            {
                spinner.setMessage(((int)Math.round(l/1000.0)-1)+"secs remaining of warmup");
            }
        };
        spinner.setButton(DialogInterface.BUTTON_POSITIVE, "Start Warmup", (DialogInterface.OnClickListener)null) ;
        spinner.show();

        Button button = spinner.getButton(DialogInterface.BUTTON_NEUTRAL);
        button.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v) 
            {
                if(start_match)
                {
                    spinner.dismiss();
                }
                else
                {
                    start_match = true;
                    Button button = spinner.getButton(DialogInterface.BUTTON_POSITIVE);
                    button.setText("Start Match");
                    timer.start();
                }
            }
        });

        spinner.setOnCancelListener(new DialogInterface.OnCancelListener() 
        {   
            @Override
            public void onCancel(DialogInterface dialog) 
            {
                timer.cancel();
                ChooseServer();
            }
        });

    }
    else
    {
        ChooseServer();
    }
}

这会打开网球比赛的热身计时器。当第一次按下按钮时,计时器应该启动。当再次按下按钮时,dailog 应该会取消。目前该对话框立即被关闭。有任何想法吗? 提前感谢您的帮助!

【问题讨论】:

    标签: java android dialog progressdialog


    【解决方案1】:

    据我对进度对话框的了解,这应该是正常行为。

    由于 ProgressDialog 继承自 AlertDialog -> Dialog 并且默认情况下,当用户按下对话框上的按钮时,它们会被关闭,无论它是哪个按钮(正/负等)。

    建议:拦截触摸事件并检测触摸事件的源位置(即用户触摸了哪个按钮),我们应该能够覆盖此行为。

    【讨论】:

      猜你喜欢
      • 2013-09-05
      • 2015-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-06
      • 1970-01-01
      • 1970-01-01
      • 2022-01-01
      相关资源
      最近更新 更多