ProgressDialog无法停止
我的应用程序正在从网络服务器加载一些数据。这次我想要一个进度对话框,以避免应用程序用户出现黑屏。
Button ok = (Button) findViewById(R.id.ok);
ok.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
MyDialog = ProgressDialog.show( yassou.this, " " , " Loading. Please wait ... ", true);
MyDialog.show();
// myIntent.username.getText();
try {
Send();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Status();
//MyDialog=null;
}
});
这是“onclick”正在加载数据的 btn。Send()
;是一种将用户输入的一些数据发送到我的服务器的方法,Status();
是第二种方法,它将我定向到新页面。不幸的是,当我按下“确定”按钮时,应用程序首先进入第二页,然后出现一个不停的进度对话框。请问我错在哪里?
my app is loading some data from a web server.this time i would like to have a progress dialog in order to avoid a black screen to the app users.
Button ok = (Button) findViewById(R.id.ok);
ok.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
MyDialog = ProgressDialog.show( yassou.this, " " , " Loading. Please wait ... ", true);
MyDialog.show();
// myIntent.username.getText();
try {
Send();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Status();
//MyDialog=null;
}
});
this is the btn witch "onclick" is loading the data.Send()
; is a method that sends some data that the user enters to my server,andStatus();
is a second method that directs me to a new page.unfortunately,as i press the ok button,the app first goes to the second page and secondly appears a non stop progress dialog.Where is my wrong please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您不再需要对话框时,您必须关闭它们。它出现在您被发送到“第二页”之后,因为所有
onClick()
代码都是在 UI 发生更改之前执行的。在
AsyncTask
或线程中完成所有Send()
和Status()
工作(最后,将关闭对话框),因为在执行该代码时,UI 将被锁定,并且无法显示对话框。此外,如果作业太长,您可能会收到应用程序未响应 (ANR) 消息。一个好的规则是,在 UI 线程中执行的任何方法的持续时间都应少于 200 毫秒,以保证响应能力,并且不会导致用户反应迟缓。
创建对话框(来自 Android Dev)
You have to dismiss dialogs when you don't need them anymore. It appears after you are sent to the "second page" because all the
onClick()
code is executed before changes to the UI happen.It's important that you do all the
Send()
andStatus()
work in anAsyncTask
or in a thread (which, at the end, will dismiss the dialog), because while that code is being executed the UI will be locked, and won't be able to show the dialog. Moreover, if the job is too long you could get an Application Not Responding (ANR) message.A good rule is that any method executed in UI thread should last less than 200ms, to guarantee responsiveness and not to result sluggish to the user.
Creating Dialogs (from Android Dev)
试试这个
try this