2016-04-27 148 views
0

我想在ACTION_UP中显示进度对话框,对于一些奇怪的原因,它不工作,我没有看到日志中的任何错误,ACTION_UP块中的所有内容都在工作,除了进度对话?任何人有任何想法发生了什么?ProgressDialog没有显示 - Android

我甚至加吐司,以测试它和它的作品就好了... ...

button.setOnTouchListener(new View.OnTouchListener() { 
    public boolean onTouch(View view, MotionEvent event) { 
     if (event.getAction() == android.view.MotionEvent.ACTION_DOWN) { 
      //works here 
      //progress = ProgressDialog.show(context,"Processing...","Preparing your file", true); 
     } else if (event.getAction() == android.view.MotionEvent.ACTION_UP ) { 

      Toast toast; 
      duration = Toast.LENGTH_LONG; 
      toast = Toast.makeText(context, text, duration); 
      toast.show();//this work and the toast is getting displayed 

      progress = ProgressDialog.show(context,"Processing...","Preparing your file", true); 

     } 
     return true; 
    } 

}); 

回答

0

出于某种原因,有时progressDialog不会显示,如果你的呼吁显示,如果主线程我不知道为什么,但我遇到同样的问题一时间前,我的工作是周围软组织使用处理器和一个可运行

new Handler().postDelayed(new Runnable(){ 
     @override 
     public void run() { 
      progressDialog.show(); 
     } 
},100); 
+0

我能够调用显示在主线程在我的项目... –

+0

正如我有时说,有时工作,它不:) – thunder413

+0

或者你可以使用真棒素材库https://开头github.com/afollestad/material-dialogs – thunder413

0

我倾向于显示对话框通知如下图所示,你会把subShowdialog代码()调用显示;你在哪里展示你的吐司。应该管用。

private void subShowdialog() { 
    final ProgressDialog progDailog = ProgressDialog.show( 
      context, "Processing...","Preparing your file", true); 

    new Thread() { 
     public void run() { 
      try { 
       sleep(1000); 
       //Start whatever action here 
       progDailog.dismiss(); 
      } catch (Exception e) { 
      } 

     } 
    }.start(); 
} 
+0

糟糕,我看到我发布了我的答案,其他人已经添加了正确的答案(教我在咖啡时开始回答)。 –