2016-11-07 55 views
0

我有一个活动。它使用nfc标签。我想在方法CertificateGeneration中创建进度对话框,以显示用户的步骤。这是我的代码。在方法中创建ProgressDialog

private void CertificateGeneration(Tag mytag) 
{ 

    ProgressDialog progress = new ProgressDialog(CertificateGenerationActivity.this); 
    progress.setMessage("in progress... "); 
    progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); 
    progress.setIndeterminate(true); 
    progress.show(); 

    Method1(); 
    progress.setMessage("Method1 is executed "); 

    Method2(); 
    progress.setMessage("Method2 is executed ");} 

,但是当我在debuge模式下执行CertificateGeneration方法我看到所有的线条都没有在屏幕上的任何变化解析。 它不会在屏幕上显示进度消息并执行方法1。为什么? 在方法结束时(执行方法1和方法2)它显示进度消息。并只显示“方法2已执行”。

如何编辑我的代码?或者它在方法(不是结束od方法)中运行时显示diplay消息的解决方案?

我也写了一个简单的方法。它没有任何方法。但它是完全地执行,只有当你有一个沉重的任务,做到使用AsyncTask显示“progress2”

private void DisplayMsg(final String msg) 
{ 
    progress = new ProgressDialog(CertificateGenerationActivity.this); 
    progress.setMessage("Progress1"); 
    progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); 
    progress.setIndeterminate(true); 
    progress.show(); 
    String f="test"; 

    progress.setMessage("progress2"); 

} 
+0

我认为这将取决于方法1和方法2执行的时间以及阻塞方法。如果你在这些方法中解释你在做什么会更好。这些方法中的 – gitter

+0

我使用智能卡中的applet进行连接。但我也写了一个简单的方法,它被免除了。 – Fatemeh

回答

0

AsyncTask具有有用的方法,如publishProgress()

+0

谢谢你的答案。我写在新的帖子,但我也有问题。我的帖子是:http://stackoverflow.com/questions/40482166/progress-dialog-not-show-on-screen?noredirect = 1# comment68208414_40482166 – Fatemeh